Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- #include <Adafruit_NeoPixel.h>
- #ifdef __AVR__
- #include <avr/power.h>
- #endif
- #define PIN 2
- #define LED 13
- #define BRIGHTNESS 5
- #define PRE_LOAD_PIXEL 26
- #define WAIT_LOAD_PIXEL 70
- #define LAST_PIXEL 110
- #define LOAD 'L'
- #define PLAN 'P'
- Adafruit_NeoPixel strip = Adafruit_NeoPixel(LAST_PIXEL, PIN, NEO_GRB + NEO_KHZ800);
- int x = 0;
- int loaded = 0;
- int planVetted = 0;
- int countProcess = 1;
- int buttonPin = 3;
- bool execute = false;
- bool prevExecute = false;
- void setup() {
- // put your setup code here, to run once:
- // Define pin #3 as input
- pinMode(buttonPin, INPUT_PULLUP);
- // Define pin #13 as output, for the LED
- pinMode(LED, OUTPUT);
- strip.begin();
- strip.setBrightness(BRIGHTNESS);
- strip.show();
- // Serial.begin(9600);
- // Attach a function to trigger when something is received.
- //Wire.begin();
- //Wire.onReceive(receiveEvent);
- }
- void loop() {
- // // Read the value of the input. It can either be 1 or 0.
- int buttonValue = digitalRead(buttonPin);
- if (buttonValue == LOW) {
- // If button pushed, turn LED on
- digitalWrite(LED, HIGH);
- execute = true;
- // if (prevExecute == false) {
- // execute = true;
- // prevExecute = true;
- // }
- } else {
- // Otherwise, turn the LED off
- digitalWrite(LED, LOW);
- execute = false;
- // prevExecute = false;
- }
- if (execute) {
- // colorWipePreLoad
- colorWipeDataFlowForward(strip.Color(0, 250, 250), 50, 0, PRE_LOAD_PIXEL); // Light Blue
- // // Send a signal to slave for LOAD
- // Wire.beginTransmission(9);
- // Wire.write(LOAD);
- // Wire.endTransmission();
- int count = 3;
- while (count > 0) {
- colorWipeDataFlowForward(strip.Color(0, 250, 0), 10, PRE_LOAD_PIXEL, WAIT_LOAD_PIXEL); // Green
- delay (100);
- colorWipeDataFlowReverse(strip.Color(0, 0, 0), 10, WAIT_LOAD_PIXEL, PRE_LOAD_PIXEL); // OFF
- count--;
- }
- // // Wait for slave Data Loaded successfully signal
- // if (x == '1') {
- // Move forward with data until planning
- colorWipeDataFlowForward(strip.Color(0, 250, 250), 50, PRE_LOAD_PIXEL, LAST_PIXEL); // Light Blue
- // Notify Slave to start planning & Financial Vetting
- // TBD
- // Send a signal to slave for LOAD
- // Wire.beginTransmission(9);
- // Wire.write(PLAN);
- // Wire.endTransmission();
- //
- // while(x == '2') {
- // //Wait for Slave to complete financial vetting
- // delay(500);
- // }
- delay(3000);
- // Fetch data and return response
- colorWipeDataFlowReverse(strip.Color(0, 0, 0), 50, LAST_PIXEL, 0); // OFF
- countProcess--;
- }
- // Trigger motor to deliver payment options
- //TBD
- // Reset execute
- execute = false;
- prevExecute = false;
- delay(500);
- }
- void receiveEvent(int bytes) {
- x = Wire.read(); // read one character from the I2C
- }
- // Fill the dots one after the other with a color
- void colorWipeDataFlowForward(uint32_t c, uint8_t wait, int start, int finish) {
- for (uint16_t i = start; i < finish; i++) {
- strip.setPixelColor(i, c);
- strip.show();
- delay(wait);
- }
- }
- // Fill the dots one after the other with a color
- void colorWipeDataFlowReverse(uint32_t c, uint8_t wait, int start, int finish) {
- for (uint16_t i = start; i > finish; i--) {
- strip.setPixelColor(i, c);
- strip.show();
- delay(wait);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement