flying dog Posted July 30, 2014 Posted July 30, 2014 As in the language? I'm playing with an Arduino and it basically is C. I am wanting to write some code for an HSI. But I'm stuck on how to do it. For now - and probably always - there is a ring of 12 LEDs. Each addressable and colour mappable. At normal (S&L) two leds are on. 3 and 9. (think of a clock) Climbing is like 4 and 8, etc Descending is 2 and 10, etc. But with only 12 LED's the resolution is a bit poor. 30 degrees / LED. As the brightness is adjustable, I can "Bleed" the colours, but can't get my head around how to do that. I'll upload what I have so far soon. At work now so am limited in time and don't have my notes with me.
rankamateur Posted July 30, 2014 Posted July 30, 2014 Used to be that only real men programmed in C, the only programmer that I knew personally who used it was a lovely lady linguist.
horsefeathers Posted July 31, 2014 Posted July 31, 2014 Not for years, but did a lot of work with VAX-C and Foxboro process controllers, etc. I can have a look if u wish..
flying dog Posted July 31, 2014 Author Posted July 31, 2014 Here is the initial code: Sorry if it is messed up. I have been trying for a while to upload and not having any luck. // HSI sketch to display Horizontal Attitude on an LED ring. int ZVO = 3; int OS = 0; int LED_Loop = 12; int QL = LED_Loop/4; void setup() { // put your setup code here, to run once: } void loop() { // put your main code here, to run repeatedly: } //================================================================== //================================================================== // // end of code // //================================================================== /* This is the caculator to display the correct LEDs on the display. ================================================================= You tell it how many LEDs are in the circle, and the "offset" number which is how far from the 12 o'clock position the first LED is. This rouine does the rest. REQUIRED: Number of LEDs in loop to be defined as LED_Loop LED_Loop / 4 as QL An OFFSET value to be set as OS A Zero Value Offset so when level this is the LED to use (ZVO) All values are counted CLOCKWISE aound the circle. */ // Called with X and Y values // Returns LED values //================================================================== int HSI(int x,int y) { // // Basic Pitch int _A1 = (x / (90/QL)) + ZVO; int _A2 = LED_Loop - _A1; // Basic Roll int _B1 = (y / (90/QL)) + ZVO; int _B2 = (_B1+QL+QL); } //================================================================== //================================================================== // // end of code // //==================================================================
flying dog Posted July 31, 2014 Author Posted July 31, 2014 The variables: ZVO is to "offset" when on a flat surface. So when "x" is saying level, it offsets to +3 and so LED 3 is used. (9 is on the opposite side. Easily enough calculated) Sorry for the slack way I have done it. I am still at the "starting out" phase of writing the program. There is a bit more added in later where _A1 and _B1 are averaged together to give the result. As with the other two. So basically it is something like: int _C1 = (average(_A1+_B1); int _C2 = (average(_A2+ _B2); And _C1 and _C2 are the two leds to use. But as you can see that is 30 degrees / LED accuracy. Which is pretty bad. I want to work out how to "include" extra LED's so at (say) 15 degrees climb: LEDs 3,4 9 and 8 are on. I hope you get my idea. Hear back from you soon I hope.
Kyle Communications Posted July 31, 2014 Posted July 31, 2014 Search the web for code there is heaps out there...this one is Mikrobasic but it is very similar to C in reality its not std basic but you should be able to sort out a lot of the code....cut and paste rules the micro world http://www.libstock.com/projects/view/760/usb-gyroscope-l3g4200d
Kyle Communications Posted July 31, 2014 Posted July 31, 2014 This is a good reference for you Might make you think a little different on your approach http://www.freescale.com/files/sensors/doc/app_note/AN3461.pdf
flying dog Posted July 31, 2014 Author Posted July 31, 2014 Kyle, the gyroscope side of things isn't the issue, but more the display part. I'll look at the link all the same though. https://www.adafruit.com/products/1643 Thanks.
Kyle Communications Posted July 31, 2014 Posted July 31, 2014 Another one Most of your code is in a lot of these projects you just need to find what you want then cut and paste it http://www.multiwii.com/software
flying dog Posted July 31, 2014 Author Posted July 31, 2014 Kyle, This is the "ring" I am going to use. https://www.adafruit.com/products/1643 So as I said, I will get 30 degrees / LED which just isn't good enough. I need to make the "active" LED "bleed" its colours into the next one to show the intermediate values.
Kyle Communications Posted July 31, 2014 Posted July 31, 2014 You will have to come up with a calculation that turns your error output or angle output to a reference that can then be used to operate a bit on the port or you could do it a easier way just use a lm3914 barograph display driver it only needs a voltage input on a scale it can be calibrated as such...the output of your gyro sensor can go into the adc then you can use a pam to drive the lm3914 for a easier display
Kyle Communications Posted July 31, 2014 Posted July 31, 2014 Adafruit are a real push in the homebrew/kit electronics market...They have a heap of Eagle libraries I use for my pcb stuff. Now I see you display it is individually addressed and colour RGB must be some sort of I2C bus. Now it would be a trick to display what you want using this led module as it needs to be "decoded" with your software to be able to drive the appropriate display... Bit out of my level of programming....I am much better with hardware than the software although I can usually get stuff working ok. Got a lift controller working at my farm it is run with arduino and xbee units. The lift carriage up and down is wireless operation the upstairs and downstairs controls are wired to the main arduino master control. Lift carriage has a gate interlock etc. This was taken when I first got it going..it is used all the time just needs a bit of tidying up which happens from time to time when we get up there
flying dog Posted July 31, 2014 Author Posted July 31, 2014 Thanks Kyle. Yeah, well I am using an Arduino to do the "number crunching" and driving the "display". I am just playing with that ring of LEDs as a good looking "display". I am making an "analogue clock" using the 60 LED ring. It is just I am not fluent enough with "cheating" with numbers getting INT() values, remainders and all that. So the question still stands. Can anyone help me with how to get the answer on how to resolve the X and Y attitudes to be displayed on a ring of LEDs with only 12 LEDs in the circle. Coz alas 30 degrees / LED isn't good resolution.
daza Posted August 2, 2014 Posted August 2, 2014 I don't have one of these displays to test, and I'm no expert... But give this a try - https://www.dropbox.com/sh/4q2yqq3pxmvr0vc/AAAWd3eWNc_gODwGMo0BF-WEa The Library gives a function to call with Pixel number and Colour, So basically it's just dividing the Pitch and Roll values by 15Deg to get a 0 -11 range for the 15Deg steps, Then if they fall between Pixels (an odd number) then light the Pixel either side at reduced brightness If the Pitch and Roll give an even number then just light that one Pixel at full brightness on each side. You'll have to add your code to get the Pitch and Roll values. (this sketch assumes degrees output, change for radians) This should be easy to change for different colours, or to vary the colour, or to change the step size. Have fun! Daza
daza Posted August 2, 2014 Posted August 2, 2014 Just threw it together from your post and a google for a library, I'm a lazy coder and always look for an existing library! Daza
flying dog Posted August 2, 2014 Author Posted August 2, 2014 NP, but you seem to be better at this than me. I'll send you what I have and need a bit of help. Appreciated.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now