Skip to content

Instantly share code, notes, and snippets.

@theduckylittle
Created July 25, 2013 01:51
Show Gist options
  • Save theduckylittle/6076256 to your computer and use it in GitHub Desktop.
Save theduckylittle/6076256 to your computer and use it in GitHub Desktop.
Basic Arduino loop() function
uint32_t counter = 0; /* ostensibly, OM */
char counter_buff[21];
/*
* cmd_byte
* One of:
* I - On
* O - Off
*/
int cmd_byte = 0;
int led = 13;
int light_status = 0;
/* change the light state. */
void blinky() {
if(light_status == 0) {
digitalWrite(led, HIGH);
light_status = 1;
} else {
digitalWrite(led, LOW);
light_status = 0;
}
counter+=1;
}
void loop() {
if(Serial.available() > 0) {
cmd_byte = Serial.read();
if(cmd_byte == 'R') {
sprintf(counter_buff, "%lu", counter);
Serial.println(counter_buff);
} else if(cmd_byte == 'Z') {
counter = 0;
}
}
}
void setup() {
pinMode(led, OUTPUT);
attachInterrupt(0, blinky, FALLING);
Serial.begin(9600);
while(Serial.available() <= 0) {
Serial.println("READY");
delay(500);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment