Advertisement
Guest User

Untitled

a guest
Feb 12th, 2013
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.24 KB | None | 0 0
  1. //////////////////////////declare global variables/////////////////
  2.  
  3. import processing.serial.*;
  4. Serial mySerial;
  5.  
  6. //begin at the beginning...
  7. int start = 0;
  8. int end = int(random(101));
  9.  
  10. //////////////////////////setup/////////////////
  11.  
  12. void setup() {
  13.  
  14.   ////environmen///
  15.   size(200, 200);
  16.   background(0);
  17.   frameRate(30);
  18.  
  19.   ////create serial port for LED communications///
  20.   println(Serial.list());
  21.   mySerial = new Serial(this, Serial.list()[0], 9600);
  22.  
  23.   delay(1000); //give it oodles of time to settle down
  24. }
  25.  
  26. //////////////////////////draw loop/////////////////
  27.  
  28. void draw() {
  29.  
  30.   // test A
  31.   if (end >= start) {
  32.  
  33.     for (int i = start; i < end; i++) {
  34.       int LED = int(i);
  35.       mySerial.write(LED);
  36.  
  37.       if (i == end -1) {
  38.         delay(5000);
  39.       }
  40.       else
  41.       {
  42.         delay(50);
  43.       }
  44.     } // end for loop
  45.    
  46.     start = end;
  47.     end = int(random(101));
  48.  
  49.   }
  50.  
  51.   // test B
  52.   if (end <= start) {
  53.  
  54.     for (int i = start; i > end; i--) {
  55.       int LED = int(i);
  56.       mySerial.write(LED);
  57.  
  58.       if (i == end + 1) {
  59.         delay(5000);
  60.       }
  61.       else
  62.       {
  63.         delay(50);
  64.       }
  65.     } //end for loop
  66.    
  67.     start = end;
  68.     end = int(random(101));
  69.   }
  70.  
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement