Advertisement
Guest User

Untitled

a guest
Nov 3rd, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. { ; symbols - text strings to represent a value or pin
  2. symbol LED0 = 0
  3. symbol LED1 = 1
  4. symbol LED2 = 2
  5. symbol LED3 = 3
  6. symbol LED4 = 4
  7. symbol Buzzer = 5
  8. symbol cycle_counter = b1
  9. symbol cycle_counter2 = b2
  10. symbol random_value = b3
  11. symbol selected = b4
  12. symbol activated = b5
  13. symbol seed = b6
  14. symbol randopt = b7
  15. }
  16.  
  17. let seed = 97 ; Prime number, good randomness
  18.  
  19. main:       ; A label, used with "goto [label]" to start executing code after the label
  20.  
  21. { ; low all outputs (turn off)
  22. low LED1
  23. low LED2
  24. low LED3
  25. low LED4
  26. low LED0
  27. low Buzzer
  28. }
  29.  
  30. let cycle_counter = 0   ; sets the counter to 0 (important so that "for ..." statements work for the right amount of time)
  31. let cycle_counter = 0
  32.  
  33. 'for cycle_counter = 1 to 100
  34. 'pause 2000
  35. random random_value     ; chooses a value from 0-255 and sets "random_value" to that value
  36. 'next
  37.  
  38. let selected = random_value % 6 + 1
  39. if selected = 0 then
  40.     high LED0
  41. elseif selected = 1 then
  42.     high LED1
  43. elseif selected = 2 then
  44.     high LED2
  45. elseif selected = 3 then
  46.     high LED3
  47. elseif selected = 4 then
  48.     high LED4
  49. endif
  50.  
  51. ;if random_value < 52 then
  52. ;   let selected = 0
  53. ;   high LED0
  54. ;elseif random_value < 103 then
  55. ;   let selected = 1
  56. ;   high LED1
  57. ;elseif random_value < 154 then
  58. ;   let selected = 2
  59. ;   high LED2
  60. ;elseif random_value < 205 then
  61. ;   let selected = 3
  62. ;   high LED3
  63. ;elseif random_value <= 255 then
  64. ;   let selected = 4
  65. ;   high LED4
  66. ;endif
  67.    
  68. for cycle_counter2 = 1 to 3
  69.     for cycle_counter = 1 to 200
  70.          
  71.         let activated = 0
  72.         if selected = 0 and input0 = 1 then
  73.             activated = 1
  74.         elseif selected = 1 and input1 = 1 then
  75.             activated = 1
  76.         elseif selected = 2 and input2 = 1 then
  77.             activated = 1
  78.         elseif selected = 3 and input3 = 1 then
  79.             activated = 1
  80.         elseif selected = 4 and input4 = 1 then
  81.             activated = 1
  82.         endif
  83.    
  84.         if activated = 1 then
  85.            
  86.             ; random number generator
  87.             pause 2000
  88.             let randopt = cycle_counter % 3
  89.             if randopt = 0 then
  90.                 let randopt = 61
  91.             elseif randopt = 1 then
  92.                 let randopt = 91
  93.             elseif randopt = 2 then
  94.                 let randopt = 79
  95.             endif
  96.             let cycle_counter = cycle_counter + random_value
  97.             let cycle_counter = cycle_counter * randopt
  98.             let cycle_counter = cycle_counter * seed
  99.             'let cycle_counter = cycle_counter * seed
  100.             let random_value = random_value + cycle_counter
  101.  
  102.             high Buzzer
  103.             pause 500
  104.             goto main
  105.         endif
  106.        
  107.         pause 1
  108.     next cycle_counter
  109. next cycle_counter2
  110.  
  111. goto main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement