Last active
October 21, 2024 20:59
-
-
Save cpjobling/8803a24e00f15237057dfdbb566a461b to your computer and use it in GitHub Desktop.
Experiment 1: Basic counter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Declare variable to be used as a counter. | |
// This has to be done outside `setup` and `loop` so that `counter` is visible | |
// inside both functions | |
byte counter; | |
// The setup function runs once when you press reset or power the board | |
void setup() { | |
// initialize counter | |
counter = 0; | |
// Set pins 0-5 of Port C 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 repeatedly forever | |
void loop() { | |
PORTC = counter; | |
// increment counter | |
// we could replace the next line with: counter1++; | |
// or the previous line with PORTC = counter1++; | |
counter = counter + 1; | |
// Uncomment the following three lines for a modulus of 60: | |
// if (counter > 59) { | |
// counter = 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