Advertisement
Guest User

Untitled

a guest
Jan 17th, 2017
466
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.48 KB | None | 0 0
  1. #include <Adafruit_NeoPixel.h>
  2. #include <Timers.h>
  3. int j =0;
  4. int d =0;         // Koniec projektu 02,01,2017R.
  5. int r = 0;
  6. int w = 0;
  7. int q =0;
  8. #define PINLED1 8
  9. #define PINLED2 7
  10. const int ZP = 11;
  11. const int KL = 12;
  12. const int KP = 13;
  13.  int a = 2;
  14. const int prog1 = A2;
  15. const int prog2 = A3;
  16.  
  17.  
  18. #define CCC strip.Color(255, 79, 1) // Kolor kierunku << 255 125 12
  19. #define BBB strip1.Color(255, 79, 1) // Kolor kierunku << 255 125 12
  20.  
  21. int KLewy = 0;
  22. int KPrawy = 0;
  23. int ZAP = 0;
  24. Timers <2> przerw;
  25. Adafruit_NeoPixel strip = Adafruit_NeoPixel(6, PINLED1, NEO_GRB + NEO_KHZ800);
  26. Adafruit_NeoPixel strip1 = Adafruit_NeoPixel(6, PINLED2, NEO_GRB + NEO_KHZ800);
  27.  
  28.  
  29. void setup() {
  30.   // put your setup code here, to run once:
  31.   przerw.attach(1, 121, czas);  
  32.  przerw.attach(2, 3106, odczyt);
  33.   strip.begin();
  34.   strip1.begin();
  35.  
  36.   pinMode(KL, INPUT);
  37.   pinMode(KP, INPUT);
  38.   pinMode(ZP, INPUT);
  39.   pinMode(prog1, INPUT_PULLUP);
  40.   pinMode(prog2, INPUT_PULLUP);
  41.  
  42.         // Random test LED
  43.       long R,G,B;
  44.         for (int n = 0; n < 6; n++){
  45.           R = random(380); G = random(300); B = random(300);
  46.           strip.setPixelColor(n, strip.Color(R, G, B));
  47.           strip1.setPixelColor(n, strip1.Color(R, G, B));
  48.           strip.show();strip1.show();
  49.         }
  50.        
  51.         delay(2500);
  52.         strip.clear();strip1.clear();
  53.         strip.show();strip1.show();
  54. }
  55.  
  56. void loop() {
  57.   przerw.process();
  58. }
  59. void odczyt() {
  60. if (digitalRead(prog1)==0 && digitalRead(prog2)== 0){
  61. a=2;}
  62. else if(digitalRead(prog1)==1 && digitalRead(prog2)== 0){
  63. a=1; }  //flow led + Amber
  64. else if  (digitalRead(prog1)==0 && digitalRead(prog2)== 1){
  65. a=0;}//flow led
  66. else if  (digitalRead(prog1)==1 && digitalRead(prog2)== 1){
  67. a=3;}
  68.  
  69. }
  70. void czas() { // flow led
  71.  
  72.  KLewy = digitalRead(KL);
  73.  KPrawy = digitalRead(KP);
  74.  ZAP = digitalRead(ZP);
  75.  if (a == 0){
  76.         if (KLewy == 1 && KPrawy == 0) {
  77.         Serial.println(j);
  78.           if (j <=6){
  79.             strip.setPixelColor(j, CCC);
  80.             strip.show();
  81.             j = j+1;
  82.           }
  83.           else if (j > 6 ){
  84.             j = 0;
  85.             strip.clear();
  86.             strip.show();
  87.             delay(700);
  88.           }
  89.         }
  90.        /* if (KLewy == 1) {
  91.           strip.clear();
  92.           strip.show();
  93.           j= 0;
  94.         }*/
  95.  
  96.  
  97.  
  98.   if (KPrawy == 1 && KLewy == 0) {
  99.           if (d <=6){
  100.             strip1.setPixelColor(d, BBB);
  101.             strip1.show();
  102.             d = d+1;
  103.           }
  104.           else if (d > 6 ){
  105.             d = 0;
  106.             strip1.clear();
  107.             strip1.show();
  108.             delay(700);
  109.           }
  110.         }
  111.        /* if (KPrawy == 1) {
  112.           strip1.clear();
  113.           strip1.show();
  114.           d= 0;
  115.         }*/
  116.  
  117.          if (KPrawy == 1 && KLewy == 1) {
  118.           if (r <=6){
  119.             strip1.setPixelColor(r, BBB);
  120.             strip.setPixelColor(r, CCC);
  121.             strip1.show();
  122.             strip.show();
  123.             r = r+1;
  124.           }
  125.           else if (r > 6 ){
  126.             r = 0;
  127.             strip1.clear();
  128.             strip.clear();
  129.             strip.show();
  130.             strip1.show();
  131.             delay(700);
  132.           }
  133.         }
  134.  
  135.             if (KPrawy == 0 && KLewy == 0) {
  136.               strip1.clear();
  137.           strip1.show();
  138.           strip.clear();
  139.           strip.show();
  140.           r=0;
  141.           d=0;
  142.           j=0;
  143.             }
  144. }
  145.  
  146.  
  147. else if (a == 1) { // flow led + Amber
  148.  
  149.  
  150. if (KLewy == 1 && KPrawy ==0) {
  151.        
  152. if (j <=6){
  153. strip.setPixelColor(j, CCC);
  154. strip.show();
  155. j = j+1;
  156.  }
  157. else if (j > 6 ){
  158. j = 0;
  159. if (ZAP == 1){
  160. for (int n = 0; n < 6; n++){
  161. strip.setPixelColor(n, strip.Color(20, 3, 0));
  162.  }}
  163.  else if (ZAP==0)  strip.clear();
  164. strip.show();
  165.  delay(700);
  166.  }
  167. }
  168.  
  169.  
  170.  
  171.  
  172. if (KPrawy == 1 && KLewy == 0) {
  173. if (w <=6){
  174. strip1.setPixelColor(w, BBB);
  175. strip1.show();
  176. w = w+1;
  177.  }
  178. else if (w > 6 ){
  179. w = 0;
  180.   if (ZAP==1){
  181. for (int v = 0; v < 6; v++){
  182. strip1.setPixelColor(v, strip1.Color(20, 3, 0));
  183.  }
  184. strip1.show();}
  185. else if (ZAP==0) {
  186. strip1.clear();
  187. strip1.show();
  188. }
  189.  
  190.  delay(700);
  191. }
  192.  }
  193.  
  194.  
  195.  
  196. if (KPrawy == 1 && KLewy == 1) {
  197. if (q <=6){
  198. strip1.setPixelColor(q, BBB);
  199. strip1.show();
  200. strip.setPixelColor(q, CCC);
  201. strip.show();
  202. q = q+1;
  203.  }
  204. else if (q > 6 ){
  205. q = 0;
  206. if (ZAP == 1){
  207. for (int v = 0; v < 6; v++){
  208. strip1.setPixelColor(v, strip1.Color(20, 3, 0));
  209. strip1.show();
  210. strip.setPixelColor(v, strip.Color(20, 3, 0));
  211. strip.show();
  212. }}
  213. else if (ZAP == 0)
  214. {  strip1.clear();
  215.        strip.clear();
  216.         strip1.show();
  217.         strip.show();
  218. }
  219.  delay(700);
  220.  
  221. }}
  222. if (KPrawy == 0 && KLewy == 0 && ZAP == 1) {
  223.         for (int s = 0; s < 6; s++){
  224.           strip1.setPixelColor(s, strip1.Color(20, 3, 0));
  225.           strip.setPixelColor(s, strip.Color(20, 3, 0));
  226.         }
  227.         strip1.show();
  228.         strip.show();
  229.         w= 0;
  230.         j=0;
  231.         q=0;
  232.        
  233. }
  234. if (KPrawy == 0 && KLewy == 0 && ZAP == 0) {
  235.        strip1.clear();
  236.        strip.clear();
  237.         strip1.show();
  238.         strip.show();
  239.         w= 0;
  240.         j=0;
  241.         q=0;
  242.        
  243. }
  244.  
  245.  
  246. }
  247.  
  248. else if (a == 2){ // Ori
  249.  
  250.  if (KLewy == 1 && KPrawy == 0) {
  251.       for (int n= 0; n<= 6; n++ ){
  252.         strip.setPixelColor(n, CCC);
  253.         strip.show();
  254.        }
  255.         Serial.print("Clear");
  256.         delay(700);
  257.         strip.clear();
  258.         strip.show();
  259.         delay(600);
  260.        }
  261.  
  262.  
  263.  else if (KLewy == 0 && KPrawy == 1) {
  264.       for (int m= 0; m<= 6; m++ ){
  265.         strip1.setPixelColor(m, BBB);
  266.         strip1.show();
  267.        }
  268.         delay(700);
  269.         strip1.clear();
  270.         strip1.show();
  271.         delay(600);
  272.        }
  273.  
  274.  else if (KLewy == 1 && KPrawy == 1) {
  275.       for (int n= 0; n<= 6; n++ ){
  276.         strip.setPixelColor(n, CCC);
  277.         strip.show();
  278.        strip1.setPixelColor(n, BBB);
  279.         strip1.show();
  280.        }
  281.         delay(700);
  282.         strip.clear();
  283.         strip.show();
  284.          strip1.clear();
  285.         strip1.show();
  286.         delay(600);
  287.        }
  288.  
  289. else if (KLewy == 0 && KPrawy == 0) {
  290.  strip.clear();
  291.         strip.show();
  292.          strip1.clear();
  293.         strip1.show();
  294. }
  295.  
  296. }
  297.  
  298.  
  299. else if (a == 3){ // Ori kierunki + DRL
  300.  
  301.  if (KLewy == 1 && KPrawy == 0) {
  302.       for (int n= 0; n<= 6; n++ ){
  303.         strip.setPixelColor(n, CCC);
  304.         strip.show();
  305.        }
  306.         Serial.print("Clear");
  307.         delay(700);
  308.         strip.clear();
  309.         strip.show();
  310.         delay(600);
  311.        }
  312.  
  313.  
  314.  else if (KLewy == 0 && KPrawy == 1) {
  315.       for (int m= 0; m<= 6; m++ ){
  316.         strip1.setPixelColor(m, BBB);
  317.         strip1.show();
  318.        }
  319.         delay(700);
  320.         strip1.clear();
  321.         strip1.show();
  322.         delay(600);
  323.        }
  324.  
  325.  else if (KLewy == 1 && KPrawy == 1) {
  326.       for (int n= 0; n<= 6; n++ ){
  327.         strip.setPixelColor(n, CCC);
  328.         strip.show();
  329.        strip1.setPixelColor(n, BBB);
  330.         strip1.show();
  331.        }
  332.         delay(700);
  333.         strip.clear();
  334.         strip.show();
  335.          strip1.clear();
  336.         strip1.show();
  337.         delay(600);
  338.        }
  339.  
  340. else if (KLewy == 0 && KPrawy == 0 && ZAP == 1) {
  341.   delay(600);
  342.  for (int s = 0; s < 6; s++){
  343.           strip1.setPixelColor(s, strip1.Color(255, 245, 200));
  344.           strip.setPixelColor(s, strip.Color(255, 245, 200));
  345.         }
  346.         strip1.show();
  347.         strip.show();
  348. }
  349. else if (KLewy == 0 && KPrawy == 0 && ZAP == 0) {
  350.  
  351.          strip.clear();
  352.         strip.show();
  353.          strip1.clear();
  354.         strip1.show();
  355. }
  356. }
  357.  
  358.  
  359.  
  360.  
  361. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement