Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. 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};
  2. unsigned int led1vals = 3215823;
  3. unsigned int led2vals = 15629783;
  4. unsigned long seconds_so_far = 0;
  5. unsigned long current_step = 0;
  6. bool done_second=false;
  7. unsigned long led1Disable = 0;
  8. unsigned long led2Disable = 0;
  9.  
  10. void delaySeconds(unsigned long duration){
  11. Serial.print("delaying for");
  12. Serial.println(duration);
  13. //delay for duration * 1 second (as close as possible without the overkill of my other example)
  14. for(;duration > 0;duration--){
  15. delay(duration*1000);
  16. }
  17. seconds_so_far += duration;
  18.  
  19. }
  20.  
  21. bool led1Activates(){
  22. //check to see if led1 gets turned on in this step
  23. if(led1vals & (1 << (31 - current_step))){
  24. //turn on,
  25. Serial.println("1 turned on");
  26. return true;
  27. }
  28. return false;
  29. }
  30.  
  31. bool led2Activates(){
  32. //check to see if led2 gets turned on in this step
  33. if(led2vals & (1 << (31 - current_step))){
  34. //turn on.
  35. Serial.println("2 turned on");
  36. return true;
  37. }
  38. return false;
  39. }
  40.  
  41. void setup() {
  42. // put your setup code here, to run once:
  43. Serial.begin(9600);
  44. }
  45.  
  46. void loop() {
  47. // put your main code here, to run repeatedly:
  48. delaySeconds(1);
  49. if(steps_absolute[current_step] >= seconds_so_far){
  50. if(led1Activates()){
  51. led1Disable = seconds_so_far + 10; //scheduling turn off point in future
  52. }
  53. if(led2Activates()){
  54. led2Disable = seconds_so_far + 10; //scheduling turn off point in future
  55. }
  56. current_step += 1;
  57. if(current_step >= 31){
  58. current_step = 0;
  59. }
  60. }
  61. if(led1Disable > seconds_so_far){
  62. //disable
  63. Serial.println("1 turned off");
  64. led1Disable = 0;
  65. }
  66. if(led2Disable > seconds_so_far){
  67. //disable
  68. Serial.println("2 turned off");
  69. led2Disable = 0;
  70. }
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement