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.
155 lines
2.5 KiB
155 lines
2.5 KiB
#include <Encoder.h>
|
|
#include <stdio.h>
|
|
|
|
|
|
Encoder rotEnc(A0, A1);
|
|
long encVal = 0;
|
|
int activeTimer=0;
|
|
int timerLens[3];
|
|
int grindCheck = 0;
|
|
|
|
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];
|
|
//printf("%c[2K", 27);
|
|
//printf("\r%s", text );
|
|
//fflush(stdout);
|
|
sprintf(str, "%c[2K\n\r%s", 27, text);
|
|
Serial.println(str);
|
|
}
|
|
|
|
|
|
void grind(int time) {
|
|
lcdPut("grinding...");
|
|
delay(time);
|
|
lcdPut("Fin...");
|
|
delay(80);
|
|
}
|
|
|
|
|
|
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 > 25 ) {
|
|
grind( timerLens[activeTimer] );
|
|
grindCheck = 0;
|
|
delay(25);
|
|
}
|
|
if( digitalRead(A2) == LOW && grindCheck >= 0 && grindCheck <= 25 ) {
|
|
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();
|
|
|
|
char str[16];
|
|
sprintf(str, "T%1d: %10d", activeTimer, timerLens[activeTimer]);
|
|
lcdPut(str);
|
|
|
|
if(buttonLeftPressed) {
|
|
buttonLeftPressed=false;
|
|
activeTimer=0;
|
|
}
|
|
if(buttonRightPressed) {
|
|
buttonRightPressed=false;
|
|
activeTimer=2;
|
|
}
|
|
if(buttonMidPressed) {
|
|
buttonMidPressed=false;
|
|
activeTimer=1;
|
|
}
|
|
if(turnedLeft) {
|
|
turnedLeft=false;
|
|
timerLens[activeTimer] -= 5;
|
|
}
|
|
if(turnedRight) {
|
|
turnedRight=false;
|
|
timerLens[activeTimer] += 5;
|
|
}
|
|
if(rotPressed) {
|
|
rotPressed=false;
|
|
grind(timerLens[activeTimer]);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void setup()
|
|
{
|
|
Serial.begin(9600);
|
|
|
|
timerLens[0] = 1000;
|
|
timerLens[1] = 250;
|
|
timerLens[2] = 2500;
|
|
|
|
pinMode(A3, INPUT);
|
|
digitalWrite(A3,HIGH);
|
|
pinMode(A4, INPUT);
|
|
digitalWrite(A4,HIGH);
|
|
pinMode(A5, INPUT);
|
|
digitalWrite(A5,HIGH);
|
|
|
|
|
|
}
|