По результатам поиска в Google - Arduino в Украине не нашлось! Пусть этот блог будет началом!!!

воскресенье, 3 января 2010 г.

Кофеварка 5

Программа - готова!
// include the library code:
#include


// constants won't change. They're used here to

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
const int buttonPin = 6; // set the number of the select pushbutton pin
const int button2Pin = 8; // set the number of the pushbutton-temp pin
const int button3Pin = 9; // set the number of the START pushbutton
const int ledPin = 7; // set the number of the led-pump pin

// variables will change:
int val = 0;// variable for reading the select pushbutton status
int buttonState;// variable to hold the select pushbutton state
int val2 = 0; //variable for reading pushbutton-temp status
int button2State;// variable to hold the pushbutton-temp state
int start = 0; //variable for reading START pushbutton status
int button3State;// variable to hold the START pushbutton state
int button3State2;// variable to hold the START pushbutton state continuously

int buttonPresses = 0;// how many times the select pushbutton has been pressed (# of programm)
int water = 0; //portions of water per cup


void setup() {

  pinMode(buttonPin, INPUT); // initialize the pushbutton pin as an input
  pinMode(button2Pin, INPUT); // initialize the pushbutton-temp pin as an input
  pinMode(button3Pin, INPUT); // initialize the start pushbutton pin as an input
  pinMode(ledPin, OUTPUT); // initialize the ledPin-nasos pin as an output

  lcd.begin(16, 2);// set up the LCD's number of rows and columns:
      lcd.setCursor(5, 0);  // set the cursor to (column, line)
      lcd.print("Privet"); // print "Privet" "Vyberi cofe"
      delay (1000);
      lcd.setCursor(3, 1);
      lcd.print("Vyberi cofe");
      delay (1000);

}




void loop() {
 
  val = digitalRead(buttonPin);    // read input value and store it in val
        delay (50);
        if (val != buttonState) // If the button state has changed...
            {if (val == HIGH) {buttonPresses++;} // check if the button is now pressed
             if (buttonPresses == 6){buttonPresses = 0;}
             button3State2=0; // reseting button3State2 to avoid starting flowing water without selected program
            // selecting program, printing name of program (tipe of cup), seting amount of water, printing amount of water  
             if (buttonPresses == 0) {lcd.clear(); lcd.setCursor(5, 0); lcd.print("1 small"); lcd.setCursor(4, 1); water = 2; lcd.print("water - "); lcd.print(water);}
             if (buttonPresses == 1) {lcd.clear(); lcd.setCursor(5, 0); lcd.print("2 big"); lcd.setCursor(4, 1); water = 12; lcd.print("water - "); lcd.print(water);}
             if (buttonPresses == 2) {lcd.clear(); lcd.setCursor(5, 0); lcd.print("1 big"); lcd.setCursor(4, 1); water = 6; lcd.print("water - "); lcd.print(water);}
             if (buttonPresses == 3) {lcd.clear(); lcd.setCursor(5, 0); lcd.print("2 middle"); lcd.setCursor(4, 1); water = 8; lcd.print("water - "); lcd.print(water);}
             if (buttonPresses == 4) {lcd.clear(); lcd.setCursor(5, 0); lcd.print("1 middle"); lcd.setCursor(4, 1); water = 4; lcd.print("water - "); lcd.print(water);}
             if (buttonPresses == 5) {lcd.clear(); lcd.setCursor(5, 0); lcd.print("2 small"); lcd.setCursor(4, 1); water = 4; lcd.print("water - "); lcd.print(water);}
      
       }
  buttonState = val;

  val2 = digitalRead(button2Pin); // reading temp sensor of cofffe machine (220v) if lamp lights temp is ok!
         delay (50);
         button2State = val2;

  start = digitalRead(button3Pin);
          delay (50);
          if (start != button3State){if (start == HIGH) {if (water>0)
              {button3State2=HIGH;}}}
  button3State = start;
// cheks if progr selected?, if temp-ok?, if start button was pressed?, opens water, delays 10 sec (water flows less then 10 sec), close water, decreases number of water, print the rest of water or end message   
if (water>0){if (val2>0){if (button3State2>0){digitalWrite(ledPin, HIGH); delay(10000); digitalWrite(ledPin, LOW); water--; lcd.setCursor(4, 1); lcd.print("water - "); lcd.print(water); if (water==0) {lcd.clear(); lcd.setCursor(1, 0); lcd.print("Coffe GOTOV!!!");}}}}
             
}


Комментарии по английски для иностранных читателей, потом переведу и весь текст