#include #include #include #include #define ONE_WIRE_BUS 11 #include #include LiquidCrystal_I2C lcd(0x27,20,4); Servo myservo; //------------------------------------------ menu variables-------------------- // this constant won't change: const int buttonPin2 = 9; const int buttonPin = 8; // the pin that the pushbutton is attached to const int ledPin = 3; // the pin that the LED is attached to // Variables will change: int buttonPushCounter = 0; // counter for the number of button presses int buttonState = 0; // current state of the button int lastButtonState = 0; // previous state of the button // variabler for -- på teller int buttonState1 = 0; // current state of the button int lastButtonState1 = 0; // previous state of the button //-----------------------------------------------meny------------------- //-------------------------------------------temperatur sensor values------------- /// Data wire is plugged into pin 11 on the Arduino #define ONE_WIRE_BUS 11 // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) OneWire oneWire(ONE_WIRE_BUS); // Pass our oneWire reference to Dallas Temperature. DallasTemperature sensors(&oneWire); //-------------------------------------------------------------------------------- ints and stuff------ int mengdeFyllt=0; // vedi brukt for å regne ut mengde fyllt??????? int sensorKlikk=2000; // 400 klikk = 1 dl int flow2=0; // verdi brukt for å regne ut mengde fyllt float time2; // inputs int val = 0; // variabel til og lagre info int in1 = 7; // rele modul int Buzzer1 = 8; //busser til sang!++ int ledPingreen= 4; // LED på pin 13 int ledPinred= 3; // LED på pin 10 // flow sensor greier volatile int flow_frequency; // Measures flow sensor pulses unsigned char flowsensor = 2; // Sensor Input float totalv=0; int N = 5; int antallrunder = 0; float totalvv; float mengdeteller=0; void flow () // Interrupt function { flow_frequency++; } void setup() { lcd.init(); // initialize the lcd lcd.backlight(); sensors.begin(); myservo.attach(5); pinMode(buttonPin2, INPUT); //button nr 1 input pinMode(buttonPin, INPUT); //button nr 2 input pinMode(ledPingreen, OUTPUT); // led output green pinMode(ledPinred, OUTPUT); // led output red digitalWrite(in1, HIGH); / / this turned the relay defult off pinMode(in1, OUTPUT); // rele low = solenoid open. pinMode(flowsensor, INPUT); digitalWrite(flowsensor, HIGH); attachInterrupt(0, flow, RISING); lcd.setCursor(3,0); lcd.print("welcome to !"); lcd.setCursor(2,1); lcd.print(".."); lcd.setCursor(0,2); lcd.print(""); lcd.setCursor(2,3); lcd.print("your text here"); Serial.begin(9600); myservo.write(120); } void loop() { // read the pushbutton input pin: buttonState = digitalRead(buttonPin); buttonState1 = digitalRead(buttonPin2); // compare the buttonState to its previous state if (buttonState1 != lastButtonState1) { // if the state has changed, increment the counter if (buttonState1 == HIGH) { // if the current state is HIGH then the button // wend from off to on: buttonPushCounter--; antallrunder=0; // resets value to LCD if(buttonPushCounter==0) //this value is used to reset button push { buttonPushCounter=4; } } else { // if the current state is LOW then the button // wend from on to off: } // Delay a little bit to avoid bouncing delay(50); } // save the current state as the last state, //for next time through the loop lastButtonState1 = buttonState1; // compare the buttonState to its previous state if (buttonState != lastButtonState) { // if the state has changed, increment the counter if (buttonState == HIGH) { // if the current state is HIGH then the button // wend from off to on: buttonPushCounter++; antallrunder=0; // resets value to LCD if(buttonPushCounter==5){ buttonPushCounter=1; } } else { // if the current state is LOW then the button // wend from on to off: } // Delay a little bit to avoid bouncing delay(50); } // save the current state as the last state, //for next time through the loop lastButtonState = buttonState; Serial.println(buttonPushCounter); if(buttonPushCounter==1) { if(antallrunder==0) // this function is only to whrite the text to the lcd once. { delay(100); lcd.clear(); lcd.setCursor(3,0); lcd.print("ProgramableBAR!"); lcd.setCursor(0,1); lcd.print(" (BETA V:2.1)"); lcd.setCursor(0,2); lcd.print("Pale Ale-->"); lcd.setCursor(0,3); lcd.print("20$ for 0,5L"); antallrunder++; } digitalWrite(ledPingreen, HIGH); digitalWrite(ledPinred, LOW); myservo.write(145); } if(buttonPushCounter==2) { if(antallrunder==0){ delay(100); lcd.clear(); lcd.setCursor(0,0); lcd.print("Pale Ale"); lcd.setCursor(0,1); lcd.print("ca 5%"); lcd.setCursor(0,2); lcd.print("add coin 20 kr"); antallrunder++; } digitalWrite(ledPinred, HIGH); digitalWrite(ledPingreen, LOW); myservo.write(50); val = analogRead(1); // read the value from the sensor Serial.println(val); //Serial.println(float(millis())); if (val<380) // leter etter en LOW, når den blir low er kanppen trykket inne/mynt i sensor { myservo.write(145); // closes the coin inlet lcd.clear(); lcd.setCursor(3,0); lcd.print("Mynt akseptert!"); lcd.setCursor(2,1); lcd.print(" wait 1 sek"); lcd.setCursor(0,2); lcd.print("All good"); lcd.setCursor(2,3); lcd.print("ProgramerBAR"); delay(1000); digitalWrite(ledPinred, LOW); //LED rød av digitalWrite(ledPingreen, HIGH); //LED grønn på flow2=flow_frequency; //variabel til utregning av volum time2=float(millis()); //tid når koden har kommet hit lagres som time2 do { digitalWrite(in1, LOW); // rele åpnes lcd.clear(); float mengde=(flow_frequency-flow2); float mengdea=(mengde*0.0025); // 0.0025 is used to calculate the amount passed throgh the flow sensor. 5DL/(sensorklikk)2000) lcd.print("Amout filled in DL"); lcd.setCursor(2,1); lcd.print(mengdea); lcd.print("DL of 5 DL"); lcd.setCursor(0,2); lcd.print(float((millis())-time2)/1000); lcd.setCursor(2,3); lcd.print("sek of 100 total"); delay(300); }while (flow_frequency-flow2