Advertisement
Guest User

Untitled

a guest
Jul 15th, 2013
3,918
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.31 KB | None | 0 0
  1. int tx = 2;
  2. void setup()
  3. {
  4.   pinMode(tx,OUTPUT);
  5. }
  6. //1=0.5µs  2=1µs 3=35µs
  7. void wait(int code){
  8.   if(code==1){
  9.   delayMicroseconds(500);
  10.   }
  11.   if(code==2){
  12.   delayMicroseconds(1000);
  13.   }
  14.   if(code==3){
  15.   delayMicroseconds(5000);
  16.   }
  17. }
  18.  
  19. void fire(int i)
  20. {
  21.  digitalWrite(tx,i);
  22.  
  23. }
  24. void i()
  25. {
  26.  fire(1);
  27.  wait(1);
  28.  fire(0);
  29.  wait(2);
  30.  fire(1);
  31.  wait(1);
  32.  fire(0);
  33.  wait(2);
  34. }
  35. void o()//3µs
  36. {
  37.  fire(1);
  38.  wait(1);
  39.  fire(0);
  40.  wait(2);
  41.  fire(1);
  42.  wait(2);
  43.  fire(0);
  44.  wait(1);
  45. }
  46. void sync()
  47. {
  48.   fire(1);
  49.   wait(1);
  50.   fire(0);
  51.   wait(3);
  52. }
  53. void transmit(int one, int two, int three, int four, int five, String c,int on)
  54. {
  55.   if(one==1){ i();  }else{ o(); }
  56.   if(two==1){ i();  }else{ o(); }
  57.   if(three==1){ i();  }else{ o(); }
  58.   if(four==1){ i();  }else{ o(); }
  59.   if(five==1){ i();  }else{ o(); }
  60.   if(c == "a"){ i();  }else{ o(); }
  61.   if(c == "b"){ i();  }else{ o(); }
  62.   if(c == "c"){ i();  }else{ o(); }
  63.   if(c == "d"){ i();  }else{ o(); }
  64.   if(c == "e"){ i();  }else{ o(); }
  65.   if(on==1){ i(); o(); sync();  }else{ o(); i(); sync();  }
  66.  
  67. }
  68. void snd(int one, int two, int three, int four, int five, String c,int on)
  69. {
  70.   transmit(one,two,three,four,five,c,on);
  71.   transmit(one,two,three,four,five,c,on);
  72.   transmit(one,two,three,four,five,c,on);
  73.   transmit(one,two,three,four,five,c,on);
  74. }
  75.  
  76. int index;
  77. String chr;
  78. int onx;
  79. void loop()
  80. {
  81.   index = index + 1;
  82.   if(index==1){  chr="a";  }
  83.   if(index==2){  chr="b";  }
  84.   if(index==3){  chr="c";  }
  85.   if(index==4){  chr="d";  }
  86.   if(index==5){  chr="e";  }
  87.   if(index>=6){  index=1; chr="a"; onx=!onx; }
  88.  
  89.   snd(1,0,0,0,0,chr,onx);
  90.   delay(5);
  91.   snd(0,0,0,0,0,chr,onx);
  92.   delay(5);
  93.   snd(0,1,0,0,0,chr,onx);
  94.   delay(5);
  95.   snd(0,0,1,0,0,chr,onx);
  96.   delay(5);
  97.   snd(0,0,0,1,0,chr,onx);
  98.   delay(5);
  99.   snd(0,0,0,0,1,chr,onx);
  100.   delay(5);
  101.   snd(1,0,0,0,1,chr,onx);
  102.   delay(5);
  103.   snd(1,0,1,0,1,chr,onx);
  104.   delay(5);
  105.   snd(0,1,0,1,0,chr,onx);
  106.   delay(5);
  107.   snd(1,1,1,0,0,chr,onx);
  108.   delay(5);
  109.   snd(0,0,1,1,1,chr,onx);
  110.   delay(5);
  111.   snd(1,1,0,1,1,chr,onx);
  112.   delay(5);
  113.   snd(0,1,1,1,0,chr,onx);
  114.   delay(5);
  115.   snd(1,0,0,0,0,chr,onx);
  116.   delay(5);
  117.   snd(1,1,0,1,0,chr,onx);
  118.   delay(5);
  119.   snd(1,0,1,1,0,chr,onx);
  120.   delay(5);
  121.   snd(1,0,0,1,1,chr,onx);
  122.   delay(5);
  123.   snd(0,1,1,0,0,chr,onx);
  124.   delay(5);
  125.  
  126.  
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement