SillyOldDuffer | 27/11/2020 14:43:51 |
10668 forum posts 2415 photos | Posted by Roger Hart on 27/11/2020 13:51:31:... Except that I would be tempted to (kindly and respectfully) strangle terse programmers (not really). Right now I am wrestling with a Python ... Excellent Python joke; not heard that one before! Terse programming I can only ask forgiveness for. I know I've gone too far when I can't understand my own code. And it's deeply shocking to come back to a year old program and immediately see the work of pure genius I believed it to be is actually clumsy, obscure and inefficient. Anyway, in defence of my terse example above, I thought I should test it. Found a 7 segment display and breadboarded it with a Nano. Of course it didn't work! However the mistake was my 7-segment display happens to be a common anode type rather than the common cathode display used by Malc. Common cathode LEDS are earthed and lit up by putting positive volts on the segments. Common anode are the other way round, ie the Common Anode is made positive and the segments are pulled down to earth to light them. The displays are inverts of each other. Oh dear. Rather than needing a major re-write, my code is fixed by adding a single statement. void setSegments( uint8_t group, int delaymS = 1000 ) { group =~ group; // Inverts group for common Anode The tilde is the 'bitwise NOT operator'. It flips binary bits so 1010 becomes 0101 and vice versa. I claim brownie points for an example than does LEDs with either positive or negative logic. Apologies to Malc, we should be keeping his thread simple! Dave |
Malc | 27/11/2020 15:45:41 |
113 forum posts 6 photos | Hi Dave, Thanks for your amendment to the sketch, I hadn't got that far. I typed in your sketch but it refuses to compile. It complains at the line: void setSegments (uint8 t group, int delaymS = 1000){ and gives an error message: variable or field 'setSegments' declared void. I was thinking that I may have typed the line incorrectly as your setSegments is in black and uint8 t is in blue Whereas my typed version has the setSegments in red and the uint8 t in black. I know these text colours in the sketches have some significance so I am just looking into it. Malc. |
Derek Scott | 15/03/2021 13:11:28 |
1 forum posts | Am I able to place a post in here for some assistance with an Arduino code? |
duncan webster | 16/03/2021 00:43:50 |
5307 forum posts 83 photos | Ask the question and see what happens, I'm sure plenty of people will reply |
Alan Charleston | 16/03/2021 05:04:08 |
157 forum posts 26 photos | Hi Malc, I can't get my head around Arduino programming either. The closest I got before I lost interest was this guy on YouTube: https://www.youtube.com/watch?v=d8_xXNcGYgo&list=PLGs0VKk2DiYx6CMdOQR_hmJ2NbB4mZQn- He has the gift of clearly and simply explaining how to programme in Arduino - something which is incredibly rare amongst the programming fraternity. Regards, Alan |
Please login to post a reply.
Want the latest issue of Model Engineer or Model Engineers' Workshop? Use our magazine locator links to find your nearest stockist!
Sign up to our newsletter and get a free digital issue.
You can unsubscribe at anytime. View our privacy policy at www.mortons.co.uk/privacy
You can contact us by phone, mail or email about the magazines including becoming a contributor, submitting reader's letters or making queries about articles. You can also get in touch about this website, advertising or other general issues.
Click THIS LINK for full contact details.
For subscription issues please see THIS LINK.