#include <Button.h>
#include <Encoder.h>
#include <oled.h>
#include <Relay.h>
Button startButton(10); //number is the pin number the button is connected to
Relay relayOne(17, true); // constructor receives (pin, isNormallyOpen) true = Normally Open, false = Normally Closed
Relay relayTwo(18, true); // constructor receives (pin, isNormallyOpen) true = Normally Open, false = Normally Closed
Relay relayThree(19, true); // constructor receives (pin, isNormallyOpen) true = Normally Open, false = Normally Closed
// Change these pin numbers to the pins connected to your encoders.
// Best Performance: both pins have interrupt capability
// Good Performance: only the first pin has interrupt capability
// Low Performance: neither pin has interrupt capability
Encoder knobOne(3, 4);
Encoder knobTwo(5, 6);
Encoder knobThree(7, 8);
long knobOnePosition = -999;
long knobTwoPosition = -999;
long knobThreePosition = -999;
long delayOne = 0;
long delayTwo = 0;
long delayThree = 0;
String delayString = "";
// OLED(uint8_t sda_pin, // sda pin for I2C comunication
// uint8_t scl_pin, // scl pin for I2C comunication
// uint8_t reset_pin=NO_RESET_PIN, // Reset pin (default: none)
// tWidth width=W_128, // Display width, must be one of enum: W_96 or W_128 (default: W_128).
// tHeight height=H_32, // Display height, must be one of enum: H_16, H_32 or OLED::H_64 (default: H_32).
// tDisplayCtrl displayCtrl=CTRL_SSD1306, //Display controller chip, must be one of enum: CTRL_SH1106 or CTRL_SSD1306 (default: CTRL_SSD1306).
// uint8_t i2c_address=0x3C // I2C address (default: 0x3C)
// );
OLED display(20,21,NO_RESET_PIN,OLED::W_128,OLED::H_64);
void setup() {
delay(1000);
display.begin();
startButton.begin();
relayOne.begin();
relayTwo.begin();
relayThree.begin();
while (!Serial) { }; // for Leos
Serial.begin(9600);
}
void loop() {
//Wait for start button
//if (startButton.pressed()) {
//when start button is pressed, do everything else
//display.draw_string(6,2,"Start button pressed");
//Get position of the 3 rotary encoders and translate to delay amounts (in ms)
long newPosOne = knobOne.read();
long newPosTwo = knobTwo.read();
long newPosThree = knobThree.read();
if (newPosOne != knobOnePosition) {
knobOnePosition = newPosOne;
delayOne = (knobOnePosition * 100);
delayString = "Delay #1: ";
delayString.concat(delayOne);
display.draw_string(6,6,delayString.c_str());
}
if (newPosTwo != knobTwoPosition) {
knobTwoPosition = newPosTwo;
delayTwo = (knobTwoPosition * 100);
delayString = "Delay #2: ";
delayString.concat(delayTwo);
display.draw_string(6,8,delayString.c_str());
}
if (newPosThree != knobThreePosition) {
knobThreePosition = newPosThree;
delayThree = (knobThreePosition * 100);
delayString = "Delay #3: ";
delayString.concat(delayThree);
display.draw_string(6,10,delayString.c_str());
}
//When start button is pressed
//Delay by amount set by encoder 1
delay(delayOne);
//Activate solenoid 1 for 100ms
relayOne.turnOn();
delay(100);
relayOne.turnOff();
//Delay by amount set by encoder 2
delay(delayTwo);
//Activate solenoid 2 for 100ms
relayTwo.turnOn();
delay(100);
relayTwo.turnOff();
//Delay by amount set by encoder 3
delay(delayThree);
//Activate solenoid 3 for 100ms
relayThree.turnOn();
delay(100);
relayThree.turnOff();
//}
// if (startButton.read() == Button::RELEASED)
// display.draw_string(6,12,"Start button released");
// display.draw_string(6,2," ");
//
}