Advertisement
Guest User

Untitled

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