r/ArduinoProjects • u/noobsie_boi • Aug 10 '22
8 bit binary counter
Hey there! I'm new to this subreddit and I've just started to work with my Arduino UNO R3. I've created an 8bit binary counter(inspired by another fellow Arduino user).
Here's the repository link:- https://github.com/Noobsiecoder/arduino-projects/tree/main/src%2F8bit-manipulator
19
u/ChezLong Aug 10 '22
4 bit surely? (cue for "don't call me Shirley" replies...)
3
9
6
u/planeturban Aug 10 '22 edited Aug 10 '22
Jokes about 8/4 bit aside. This is a nice way to learn about port manipulation. If you were to connect your leds to A0-3 and do something like this, you'd end up with a smaller program:
void setup()
{
DDRC = 15; // set analog pin 0-3 to outputs, 15 == binary 1111 hence all as outputs.
}
void loop()
{
for (int j = 0; j < 16; j++) {
PORTC = 0; // turn all leds off
PORTC = j; // write value to leds.
delay(500);
}
delay(1000);
}It's called port manipulation if you want to read more about it.
(Disclaimer, I did this from memory so I might have mixed my registers up, but it looks ok. If someone sees an error, please correct. :) )
Happy coding!
Edit: checked the code, seems to work.
6
2
1
2
u/noobsie_boi Aug 11 '22
Sincere apologies, its a 4 bit binary counter. Thanks for the help redditors! :)