Created
June 8, 2022 21:28
-
-
Save cybercris/57be9836a8ed6adb0774eedfdfacbbe5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Adafruit_NeoPixel.h> | |
#include <IRremote.h> | |
#include <LiquidCrystal.h> | |
#define LED_PIN 8 | |
#define LED_COUNT 12 | |
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800); | |
LiquidCrystal lcd(7, 6, 5, 4, 2, 13); | |
int pinPiezo = 10; | |
int pinButton = 12; | |
int pinMotor = 11; | |
int pinPotentiometer = A0; | |
int pinTilt = 9; | |
int tiltState; | |
int QUICK_WASH = 85; | |
int NORMAL_WASH = 170; | |
int HEAVY_WASH = 255; | |
int RECV_PIN = 3; | |
String valueInfra; | |
IRrecv irrecv(RECV_PIN); | |
decode_results results; | |
void setup() | |
{ | |
Serial.begin(9600); | |
irrecv.enableIRIn(); | |
strip.begin(); | |
strip.show(); | |
lcd.begin(16, 2); | |
pinMode(pinPiezo, OUTPUT); | |
pinMode(pinMotor, OUTPUT); | |
pinMode(pinButton, INPUT_PULLUP); | |
pinMode(pinTilt, INPUT); | |
} | |
void loop() { | |
int potentiometerValue = analogRead(pinPotentiometer); | |
tiltState = digitalRead(pinTilt); | |
if(isButtonStartClicked() || irrecv.decode(&results)) { | |
if(tiltState == HIGH) { | |
valueInfra = String(results.value, HEX); | |
Serial.println(valueInfra); | |
if(getVelocityMotor(potentiometerValue, valueInfra) == QUICK_WASH) { | |
quickWash(); | |
} | |
if(getVelocityMotor(potentiometerValue, valueInfra) == NORMAL_WASH) { | |
normalWash(); | |
} | |
if(getVelocityMotor(potentiometerValue, valueInfra) == HEAVY_WASH) { | |
heavyWash(); | |
} | |
} else { | |
lidUpWarning(); | |
} | |
results.value = -1; | |
valueInfra = ""; | |
irrecv.resume(); | |
} | |
} | |
void lidUpWarning() { | |
writeDisplay("Tampa", "Levantada"); | |
machineAlert(); | |
clearDisplay(); | |
} | |
bool isButtonStartClicked() { | |
return digitalRead(pinButton) == LOW; | |
} | |
void quickWash() { | |
writeDisplay("Lavagem", "Rapida"); | |
delay(2000); | |
clearDisplay(); | |
fillWithWater(3000); | |
fillWithSoap(3000); | |
washing(3000, 85); | |
drainWater(3000); | |
drying(3000); | |
doneMachine(); | |
} | |
void normalWash() { | |
writeDisplay("Lavagem", "Normal"); | |
delay(2000); | |
clearDisplay(); | |
fillWithWater(6000); | |
fillWithSoap(6000); | |
washing(6000, 170); | |
drainWater(6000); | |
fillWithWater(6000); | |
fillWithSoap(6000); | |
washing(6000, 170); | |
drainWater(6000); | |
drying(6000); | |
doneMachine(); | |
} | |
void heavyWash() { | |
writeDisplay("Lavagem", "Pesada"); | |
delay(2000); | |
clearDisplay(); | |
fillWithWater(6000); | |
fillWithSoap(6000); | |
washing(6000, 255); | |
drainWater(6000); | |
fillWithWater(6000); | |
fillWithSoap(6000); | |
washing(6000, 255); | |
drainWater(6000); | |
fillWithWater(6000); | |
fillWithSoap(6000); | |
washing(6000, 255); | |
drainWater(6000); | |
drying(6000); | |
doneMachine(); | |
} | |
void fillWithWater(int delayValue) { | |
turnOnLedFillWithWater(); | |
writeDisplay("Colocando", "Agua"); | |
delay(delayValue); | |
turnOffLed(); | |
clearDisplay(); | |
} | |
void fillWithSoap(int delayValue) { | |
turnOnLedFillWithSoap(); | |
writeDisplay("Colocando", "Sabao"); | |
delay(delayValue); | |
turnOffLed(); | |
clearDisplay(); | |
} | |
void washing(int delayValue, int velocityMotor) { | |
turnOnLedWashing(); | |
writeDisplay("Lavagem", "Iniciada"); | |
startMotor(velocityMotor); | |
delay(delayValue); | |
turnOffLed(); | |
doneMotor(); | |
clearDisplay(); | |
} | |
void drainWater(int delayValue) { | |
turnOnLedDrainWater(); | |
writeDisplay("Drenando", "Agua"); | |
delay(delayValue); | |
turnOffLed(); | |
clearDisplay(); | |
} | |
void drying(int delayValue) { | |
startMotor(255); | |
writeDisplay("Secando", "Roupa"); | |
delay(delayValue); | |
doneMotor(); | |
clearDisplay(); | |
} | |
void doneMachine() { | |
writeDisplay("Lavagem", "finalizada"); | |
machineAlert(); | |
clearDisplay(); | |
} | |
void machineAlert() { | |
digitalWrite(pinPiezo, HIGH); | |
delay(1000); | |
digitalWrite(pinPiezo, LOW); | |
delay(1000); | |
digitalWrite(pinPiezo, HIGH); | |
delay(1000); | |
digitalWrite(pinPiezo, LOW); | |
} | |
int getVelocityMotor(int potentiometerValue, String infraValue) { | |
if((potentiometerValue >= 0 && potentiometerValue <= 341) || infraValue == "fd08f7") return 85; | |
else if((potentiometerValue >= 342 && potentiometerValue <= 682) || infraValue == "fd8877") return 170; | |
else if(infraValue == "fd48b7") return 255; | |
else return 255; | |
} | |
void startMotor(int valocity) { | |
analogWrite(pinMotor, valocity); | |
} | |
void doneMotor() { | |
analogWrite(pinMotor, 0); | |
} | |
void writeDisplay(String title, String subTitle) { | |
lcd.setCursor(0, 0); | |
lcd.print(title); | |
lcd.setCursor(0, 1); | |
lcd.print(subTitle); | |
} | |
void clearDisplay() { | |
lcd.clear(); | |
} | |
void turnOffLed() { | |
strip.clear(); | |
strip.show(); | |
} | |
void turnOnLedFillWithWater() { | |
strip.setPixelColor(0, 0, 0, 255); | |
strip.setPixelColor(1, 0, 0, 255); | |
strip.setPixelColor(2, 0, 0, 255); | |
strip.show(); | |
} | |
void turnOnLedFillWithSoap() { | |
strip.setPixelColor(3, 255, 127, 0); | |
strip.setPixelColor(4, 255, 127, 0); | |
strip.setPixelColor(5, 255, 127, 0); | |
strip.show(); | |
} | |
void turnOnLedWashing() { | |
strip.setPixelColor(6, 0, 255, 0); | |
strip.setPixelColor(7, 0, 255, 0); | |
strip.setPixelColor(8, 0, 255, 0); | |
strip.show(); | |
} | |
void turnOnLedDrainWater() { | |
strip.setPixelColor(9, 255, 0, 0); | |
strip.setPixelColor(10, 255, 0, 0); | |
strip.setPixelColor(11, 255, 0, 0); | |
strip.show(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment