Last active
January 15, 2016 10:53
-
-
Save vitiral/10012257 to your computer and use it in GitHub Desktop.
usertools ui_led_example4 explained -- part1
This file contains 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
#include <ui.h> // include protothread library | |
#define LEDPIN 13 // LEDPIN is a constant | |
uint16_t sub_time = 0; // subtracts time from LED periods | |
void toggleLED() { | |
boolean ledstate = digitalRead(LEDPIN); // get LED state | |
ledstate ^= 1; // toggle LED state using xor | |
digitalWrite(LEDPIN, ledstate); // write inversed state back | |
} | |
/* This function toggles the LED after 'interval' ms passed */ | |
PT_THREAD blinky_thread(pthread *pt) { | |
// Notice that this function doesn't require any static integers. Everything | |
// is stored inside of pt. | |
PT_BEGIN(pt); | |
while(1) { | |
//* Use PT_WAIT_MS instead of the timestamp, etc. | |
PT_WAIT_MS(pt, pt->get_int_input(0) - sub_time); // macro to do "wait for milliseconds" | |
toggleLED(); | |
} | |
PT_END(pt); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment