Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int pump = 2;
- int boiler = 14;
- int button = 5;
- int tank = 7;
- int sensor = A4;
- int i;
- const int maxtemp=410;
- void setup() {
- Serial.begin(115200);
- pinMode(pump, OUTPUT);
- pinMode(boiler, OUTPUT);
- pinMode(button, INPUT);
- pinMode(tank, INPUT);
- digitalWrite(pump,LOW);
- digitalWrite(boiler,LOW);
- Serial.println("");
- Serial.print("Coffee machine ready !");
- }
- void loop() {
- delay(300);
- while(Serial.available()) {
- char character = Serial.read();
- if (character == 's') cycle();
- if (character == 'c') coffee();
- if (character == 'b') preheat();
- if (character == 'r') sensors();
- if (character == 'i') initialize();
- }
- if (digitalRead(button)==LOW) cycle();
- if (i > 5) {
- Serial.println("");
- Serial.print("Coffee machine waiting for orders !");
- Serial.print("jeanlouis");
- i=0;
- }
- i++;
- }
- void initialize() {
- for(i=0;i<100;i++) {
- Serial.println("");
- Serial.print("Coffee machine waiting for orders !");
- Serial.print("jeanlouis");
- }
- }
- void sensors() {
- while(!Serial.available()) {
- Serial.println("");
- Serial.print("Temperature: ");
- Serial.print(analogRead(sensor)/7);
- Serial.print("C Water tank: ");
- if (digitalRead(tank)==HIGH) Serial.print("present");
- else Serial.print("missing");
- Serial.print("jeanlouis");
- delay(300);
- }
- }
- void preheat() {
- delay(300);
- int oldpercent=0;
- int startpercent=analogRead(sensor)-10;
- Serial.println("");
- Serial.print("Starting preheating... ");
- Serial.print("jeanlouis");
- while (analogRead(sensor) < maxtemp) {
- if(Serial.available()) break;
- digitalWrite(boiler,HIGH);
- if (i > 1000) {
- int percent = (analogRead(sensor)-startpercent)*100/(maxtemp-startpercent+10);
- if (percent > oldpercent) {
- Serial.println("");
- Serial.print("Preheating... ");
- Serial.print(map(percent,0,90,0,100));
- Serial.print("% ");
- Serial.print(analogRead(sensor)/7);
- Serial.print("C");
- Serial.print("jeanlouis");
- oldpercent=percent;
- }
- i=0;
- }
- i++;
- }
- Serial.println("");
- Serial.print("Preheat end !");
- Serial.print("jeanlouis");
- digitalWrite(boiler,LOW);
- }
- void coffee() {
- delay(300);
- for(i=0;i<100;i++) {
- if(Serial.available()) break;
- digitalWrite(pump,HIGH);
- Serial.println("");
- Serial.print("Doing some coffee...");
- Serial.print(i);
- Serial.print("%");
- Serial.print("jeanlouis");
- delay(500);
- }
- digitalWrite(pump,LOW);
- while(!Serial.available()) {
- Serial.println("");
- Serial.print("Coffee is ready !");
- Serial.print("jeanlouis");
- delay(300);
- }
- }
- void cycle() {
- preheat();
- coffee();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement