Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unsigned int steps_absolute[32] = {3,5,17,21,47,49,57,58,64,76,79,92,93,101,106,112,115,121,123,130,134,135,136,141,163,170,173,186,191,200,210,212};
- unsigned int led1vals = 3215823;
- unsigned int led2vals = 15629783;
- unsigned long seconds_so_far = 0;
- unsigned long current_step = 0;
- bool done_second=false;
- unsigned long led1Disable = 0;
- unsigned long led2Disable = 0;
- void delaySeconds(unsigned long duration){
- Serial.print("delaying for");
- Serial.println(duration);
- //delay for duration * 1 second (as close as possible without the overkill of my other example)
- for(;duration > 0;duration--){
- delay(duration*1000);
- }
- seconds_so_far += duration;
- }
- bool led1Activates(){
- //check to see if led1 gets turned on in this step
- if(led1vals & (1 << (31 - current_step))){
- //turn on,
- Serial.println("1 turned on");
- return true;
- }
- return false;
- }
- bool led2Activates(){
- //check to see if led2 gets turned on in this step
- if(led2vals & (1 << (31 - current_step))){
- //turn on.
- Serial.println("2 turned on");
- return true;
- }
- return false;
- }
- void setup() {
- // put your setup code here, to run once:
- Serial.begin(9600);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- delaySeconds(1);
- if(steps_absolute[current_step] >= seconds_so_far){
- if(led1Activates()){
- led1Disable = seconds_so_far + 10; //scheduling turn off point in future
- }
- if(led2Activates()){
- led2Disable = seconds_so_far + 10; //scheduling turn off point in future
- }
- current_step += 1;
- if(current_step >= 31){
- current_step = 0;
- }
- }
- if(led1Disable > seconds_so_far){
- //disable
- Serial.println("1 turned off");
- led1Disable = 0;
- }
- if(led2Disable > seconds_so_far){
- //disable
- Serial.println("2 turned off");
- led2Disable = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement