By continuing to use this site, you agree to our use of cookies. Find out more
Forum sponsored by:
Forum sponsored by Forum House Ad Zone

Arduino programming?

All Topics | Latest Posts

Search for:  in Thread Title in  
SillyOldDuffer27/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 ) {
// A function that
// Turn the segments on or off depending on bits set in group and a bit mask
// group = 0, sets everything on
// group = 0b00111101 turns segs C,D,E.F and decimal ON

group =~ group; // Inverts group for common Anode
digitalWrite( SEG_A, group & 0b10000000 ); // Only turns on A if first bit of group is 1
digitalWrite( SEG_B, group & 0b01000000 );
digitalWrite( SEG_C, group & 0b00100000 );

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

Malc27/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 Scott15/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 webster16/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 Charleston16/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

All Topics | Latest Posts

Please login to post a reply.

Magazine Locator

Want the latest issue of Model Engineer or Model Engineers' Workshop? Use our magazine locator links to find your nearest stockist!

Find Model Engineer & Model Engineers' Workshop

Sign up to our Newsletter

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

Latest Forum Posts
Support Our Partners
cowells
Sarik
MERIDIENNE EXHIBITIONS LTD
Subscription Offer

Latest "For Sale" Ads
Latest "Wanted" Ads
Get In Touch!

Do you want to contact the Model Engineer and Model Engineers' Workshop team?

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.

Digital Back Issues

Social Media online

'Like' us on Facebook
Follow us on Facebook

Follow us on Twitter
 Twitter Logo

Pin us on Pinterest

 

Donate

donate