You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

172 lines
3.0 KiB

#include <LiquidCrystal.h>
#include <Encoder.h>
#include <stdio.h>
LiquidCrystal lcd(9, 3, 8, 7, 6, 5, 4);
Encoder rotEnc(A0, A1);
long encVal = 0;
int activeTimer=0;
int timerLens[3];
int grindCheck = 0;
bool updateDisplay=false;
bool buttonLeftPressed=false;
void buttonLeft() {
buttonLeftPressed=true;
}
bool buttonRightPressed=false;
void buttonRight() {
buttonRightPressed=true;
}
bool buttonMidPressed=false;
void buttonMid() {
buttonMidPressed=true;
}
bool turnedLeft=false;
void turnLeft() {
turnedLeft=true;
}
bool turnedRight=false;
void turnRight() {
turnedRight=true;
}
bool rotPressed=false;
void pressRot() {
rotPressed=true;
}
void lcdPut(char* text) {
char str[35];
sprintf(str, "%s", text);
lcd.clear(); lcd.home();
lcd.print(str);
}
void grind(int time) {
lcdPut("grinding...");
digitalWrite(2, HIGH);
delay(time);
digitalWrite(2, LOW);
lcdPut("Fin...");
delay(750);
updateDisplay=true;
}
void boilerplate() {
if(rotEnc.read() < encVal) {
encVal = rotEnc.read();
turnLeft();
return;
} else if(rotEnc.read() > encVal) {
encVal = rotEnc.read();
turnRight();
return;
}
if( digitalRead(A2) == LOW && grindCheck > 17500 ) {
grind( timerLens[activeTimer] );
grindCheck = 0;
delay(25);
}
if( digitalRead(A2) == LOW && grindCheck >= 0 && grindCheck <= 17500 ) {
grindCheck++;
}
if( digitalRead(A2) == HIGH && grindCheck > 0 ) {
grindCheck = 0;
}
if( digitalRead(A3) == LOW ) {
buttonLeft();
delay(25);
}
if( digitalRead(A4) == LOW ) {
buttonMid();
delay(25);
}
if( digitalRead(A5) == LOW ) {
buttonRight();
delay(25);
}
}
void loop() {
boilerplate();
if(buttonLeftPressed) {
buttonLeftPressed=false;
activeTimer=0;
updateDisplay=true;
}
if(buttonRightPressed) {
buttonRightPressed=false;
activeTimer=2;
updateDisplay=true;
}
if(buttonMidPressed) {
buttonMidPressed=false;
activeTimer=1;
updateDisplay=true;
}
if(turnedLeft) {
turnedLeft=false;
timerLens[activeTimer] -= 5;
updateDisplay=true;
}
if(turnedRight) {
turnedRight=false;
timerLens[activeTimer] += 5;
updateDisplay=true;
}
if(rotPressed) {
rotPressed=false;
grind(timerLens[activeTimer]);
updateDisplay=true;
}
if(updateDisplay) {
char str[16];
sprintf(str, "T%1d:%5d", activeTimer, timerLens[activeTimer]);
lcdPut(str);
updateDisplay=false;
}
}
void setup()
{
//Serial.begin(9600);
timerLens[0] = 1000;
timerLens[1] = 250;
timerLens[2] = 9950;
pinMode(A3, INPUT);
digitalWrite(A3,HIGH);
pinMode(A4, INPUT);
digitalWrite(A4,HIGH);
pinMode(A5, INPUT);
digitalWrite(A5,HIGH);
pinMode(2, OUTPUT);
digitalWrite(2, LOW);
updateDisplay=true;
}