Advertisement
Guest User

Untitled

a guest
Nov 3rd, 2016
105
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 seed0 = b6
  14. symbol seed1 = b7
  15. symbol seed2 = b8
  16. symbol seed3 = b9
  17. symbol randcache = b10
  18. }
  19.  
  20. let seed0 = 97 ; Prime number, good randomness
  21. let seed1 = 61
  22. let seed2 = 91
  23. let seed3 = 79
  24.  
  25. main:       ; A label, used with "goto [label]" to start executing code after the label
  26.  
  27. { ; low all outputs (turn off)
  28. low LED1
  29. low LED2
  30. low LED3
  31. low LED4
  32. low LED0
  33. low Buzzer
  34. }
  35.  
  36. let cycle_counter = 0   ; sets the counter to 0 (important so that "for ..." statements work for the right amount of time)
  37. let cycle_counter2 = 0
  38.  
  39. random random_value     ; chooses a value from 0-255 and sets "random_value" to that value
  40. let selected = random_value % 6 - 1 ; Modulo math to get selected LED
  41. if selected = 5 then
  42.     goto main
  43. elseif selected = 255 then
  44.     selected = 0
  45. endif
  46.  
  47. if selected = 0 then
  48.     high LED0
  49. elseif selected = 1 then
  50.     high LED1
  51. elseif selected = 2 then
  52.     high LED2
  53. elseif selected = 3 then
  54.     high LED3
  55. elseif selected = 4 then
  56.     high LED4
  57. endif
  58.    
  59. for cycle_counter2 = 1 to 3
  60.     for cycle_counter = 1 to 200
  61.          
  62.         let activated = 0
  63.         if selected = 0 and input0 = 1 then
  64.             activated = 1
  65.         elseif selected = 1 and input1 = 1 then
  66.             activated = 1
  67.         elseif selected = 2 and input2 = 1 then
  68.             activated = 1
  69.         elseif selected = 3 and input3 = 1 then
  70.             activated = 1
  71.         elseif selected = 4 and input4 = 1 then
  72.             activated = 1
  73.         endif
  74.    
  75.         if activated = 1 then
  76.            
  77.             ; shake it all about
  78.             ; none of the below code means anything, the more confusing it is the more random the number it generates
  79.             let randcache = cycle_counter % 3
  80.             if randcache = 0 then
  81.                 let randcache = seed1
  82.             elseif randcache = 1 then
  83.                 let randcache = seed2
  84.             elseif randcache = 2 then
  85.                 let randcache = seed3
  86.             endif
  87.             let cycle_counter = cycle_counter + random_value
  88.             let cycle_counter = cycle_counter * randcache
  89.             let cycle_counter = cycle_counter * seed0
  90.             let random_value = random_value + cycle_counter
  91.             ; kinda random number comes out here
  92.  
  93.             high Buzzer
  94.             pause 500
  95.             goto main
  96.         endif
  97.        
  98.         pause 10
  99.     next cycle_counter
  100. next cycle_counter2
  101.  
  102. goto main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement