Would this work for what I need it to?


hey all, newbie arduino world here. i'm working on building automated liquor dispenser , i'm wondering if code work way want to. arduino uno in mail , won't here till friday or so, , wanted try work out as possible beforehand, it's plug-and-play. it's pretty simple:

3 buttons control amount dispensed (single, double, or triple ["1x", "2x", , "3x" in code, respectively])

1 button act "safety switch" liquor dispense when glass on pad ("pad" in code)

3 led's (one each mode ["1xled", "2xled", "3xled" in code])

a pump dispense liquor ("pump" in code)

an lcd display show messages based upon given actions ("lcd" in code)



any appreciated, , glad elaborate further if need be.
code: [select]
#include <liquidcrystal.h>
#include <stepper.h>

int 1xstate = 0, 2xstate = 0, 3xstate = 0, padstate = 0;
int 1xledstate = 0, 2xledstate = 0, 3xledstate = 0;
const int steps = 200;
const int 1xled = 0, 2xled = 1, 3xled = 2, pump = 3;
const int 1x = a0, 2x = a1, 3x = a2, pad = a3;
const int rs = 9, en = 8, d4 = 7, d5 = 6, d6 = 5, d7 = 4;
liquidcrystal lcd(rs, en, d4, d5, d6, d7);
stepper pump(steps, 10, 11, 12, 13);

void setup() {
  lcd.begin(16, 2);
  pump.setspeed(60);
  pinmode (1x, input);
  pinmode (2x, input);
  pinmode (3x, input);
  pinmode (pad, input);
  pinmode (pump, output);
  pinmode (1xled, output);
  pinmode (2xled, output);
  pinmode (3xled, output);
}

void loop() {
1xstate = analogread(1x);
2xstate = analogread(2x);
3xstate = analogread(3x);
padstate = analogread(pad);

if(padstate == high){
  lcd.setcursor(3,0)
  lcd.print("how  much?")
 
} else if (padstate == high && 1xstate == high) {
  lcd.setcursor(2,0)
  lcd.print("nice choice.")
  pump.step(1000)
  digitalwrite(1xledstate = high)
  delay(5000)
  digitalwrite(1xledstate = low)
 
} else if (padstate == high && 2xstate == high) {
  lcd.setcursor(3,0)
  lcd.print("rough day?")
  pump.step(2000)
  digitalwrite(2xledstate = high)
  delay(10000)
  digitalwrite(2xledstate = low)
 
} else if (padstate == high && 3xstate == high) {
  lcd.setcursor(5,0)
  lcd.print("go big")
  lcd.setcursor(2,1)
  lcd.print("or go home")
  digitalwrite(3xledstate = high)
  delay(15000)
  digitalwrite(3xledstate = low)
 
} else {
  lcd.setcursor(3,0)
  lcd.print("*bar**wench*")
  lcd.setcursor(3,1)
  lcd.print("jack daniels")
}
 
}

}

use ctrl t format sketch.

digitalwrite(1xledstate = high)
look digitalwrite usage.

avoid delay()
study sate machine techniques.
http://www.thebox.myzen.co.uk/tutorial/state_machine.html   

if these digital inputs change:
const int 1x = a0, 2x = a1, 3x = a2, pad = a3;
const byte 1x = 14, 2x = 15, 3x = 16, pad = 17;
then digitalreads on them.

did trial verify?


show schematic of circuit. 




Arduino Forum > Using Arduino > Project Guidance > Would this work for what I need it to?


arduino

Comments

Popular posts from this blog

Error compiling for board Arduino/Genuino Uno.

Installation database is corrupt

esp8266 (nodemcu 0.9) client.write très lent ???