Skip to content

Instantly share code, notes, and snippets.

@cpjobling
Last active October 26, 2023 09:37
Show Gist options
  • Save cpjobling/8803a24e00f15237057dfdbb566a461b to your computer and use it in GitHub Desktop.
Save cpjobling/8803a24e00f15237057dfdbb566a461b to your computer and use it in GitHub Desktop.
Experiment 1: Basic counter
// the setup function runs once when you press reset or power the board
byte counter1 = 0; // we need to define the variable counter1
void setup()
{
// initialize Port C pins 0-5 as outputs.
DDRC = 0b00111111; // the prefix “0b” qualifies the number as binary
PORTC = 0; // so all the LEDs are off initially
}
// the loop function runs over and over again forever
void loop() {
PORTC = counter1;
// we could replace the next line with: counter1++;
// or the previous line with PORTC = counter1++;
counter1 = counter1 + 1;
// Uncomment the following 3 lines for a modulus of 60:
// if (counter1 > 59) {
// counter1 = 0;
// }
delay(1000); // reduce the delay if you get bored waiting!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment