Advertisement
Guest User

Setup_master_v1.1

a guest
Aug 20th, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. #include <Wire.h>
  2. #include <Adafruit_NeoPixel.h>
  3. #ifdef __AVR__
  4. #include <avr/power.h>
  5. #endif
  6.  
  7. #define PIN 2
  8. #define LED 13
  9. #define BRIGHTNESS 5
  10.  
  11.  
  12. #define PRE_LOAD_PIXEL 26
  13. #define WAIT_LOAD_PIXEL 70
  14. #define LAST_PIXEL 110
  15.  
  16. #define LOAD 'L'
  17. #define PLAN 'P'
  18.  
  19. Adafruit_NeoPixel strip = Adafruit_NeoPixel(LAST_PIXEL, PIN, NEO_GRB + NEO_KHZ800);
  20.  
  21. int x = 0;
  22. int loaded = 0;
  23. int planVetted = 0;
  24. int countProcess = 1;
  25. int buttonPin = 3;
  26. bool execute = false;
  27. bool prevExecute = false;
  28.  
  29. void setup() {
  30. // put your setup code here, to run once:
  31. // Define pin #3 as input
  32. pinMode(buttonPin, INPUT_PULLUP);
  33. // Define pin #13 as output, for the LED
  34. pinMode(LED, OUTPUT);
  35.  
  36. strip.begin();
  37. strip.setBrightness(BRIGHTNESS);
  38. strip.show();
  39.  
  40.  
  41. // Serial.begin(9600);
  42.  
  43. // Attach a function to trigger when something is received.
  44. //Wire.begin();
  45. //Wire.onReceive(receiveEvent);
  46.  
  47. }
  48.  
  49. void loop() {
  50. // // Read the value of the input. It can either be 1 or 0.
  51. int buttonValue = digitalRead(buttonPin);
  52. if (buttonValue == LOW) {
  53. // If button pushed, turn LED on
  54. digitalWrite(LED, HIGH);
  55. execute = true;
  56. // if (prevExecute == false) {
  57. // execute = true;
  58. // prevExecute = true;
  59. // }
  60. } else {
  61. // Otherwise, turn the LED off
  62. digitalWrite(LED, LOW);
  63. execute = false;
  64. // prevExecute = false;
  65. }
  66.  
  67. if (execute) {
  68. // colorWipePreLoad
  69. colorWipeDataFlowForward(strip.Color(0, 250, 250), 50, 0, PRE_LOAD_PIXEL); // Light Blue
  70.  
  71. // // Send a signal to slave for LOAD
  72. // Wire.beginTransmission(9);
  73. // Wire.write(LOAD);
  74. // Wire.endTransmission();
  75.  
  76. int count = 3;
  77. while (count > 0) {
  78. colorWipeDataFlowForward(strip.Color(0, 250, 0), 10, PRE_LOAD_PIXEL, WAIT_LOAD_PIXEL); // Green
  79. delay (100);
  80. colorWipeDataFlowReverse(strip.Color(0, 0, 0), 10, WAIT_LOAD_PIXEL, PRE_LOAD_PIXEL); // OFF
  81. count--;
  82. }
  83.  
  84. // // Wait for slave Data Loaded successfully signal
  85. // if (x == '1') {
  86.  
  87. // Move forward with data until planning
  88. colorWipeDataFlowForward(strip.Color(0, 250, 250), 50, PRE_LOAD_PIXEL, LAST_PIXEL); // Light Blue
  89.  
  90. // Notify Slave to start planning & Financial Vetting
  91. // TBD
  92. // Send a signal to slave for LOAD
  93. // Wire.beginTransmission(9);
  94. // Wire.write(PLAN);
  95. // Wire.endTransmission();
  96. //
  97. // while(x == '2') {
  98. // //Wait for Slave to complete financial vetting
  99. // delay(500);
  100. // }
  101.  
  102. delay(3000);
  103.  
  104. // Fetch data and return response
  105. colorWipeDataFlowReverse(strip.Color(0, 0, 0), 50, LAST_PIXEL, 0); // OFF
  106. countProcess--;
  107. }
  108.  
  109. // Trigger motor to deliver payment options
  110. //TBD
  111.  
  112. // Reset execute
  113. execute = false;
  114. prevExecute = false;
  115. delay(500);
  116. }
  117.  
  118. void receiveEvent(int bytes) {
  119. x = Wire.read(); // read one character from the I2C
  120. }
  121.  
  122. // Fill the dots one after the other with a color
  123. void colorWipeDataFlowForward(uint32_t c, uint8_t wait, int start, int finish) {
  124. for (uint16_t i = start; i < finish; i++) {
  125. strip.setPixelColor(i, c);
  126. strip.show();
  127. delay(wait);
  128. }
  129. }
  130.  
  131. // Fill the dots one after the other with a color
  132. void colorWipeDataFlowReverse(uint32_t c, uint8_t wait, int start, int finish) {
  133. for (uint16_t i = start; i > finish; i--) {
  134. strip.setPixelColor(i, c);
  135. strip.show();
  136. delay(wait);
  137. }
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement