Automatisk Espresso Loader (7 / 7 steg)
Steg 7: SPIN kod
SNURRA kodenCON
Flavor1 = 0
Flavor2 = 1
Flavor3 = 2
Shot2 = 3
Shot4 = 4
Start = 5
Avbryta = 6
Servo1 = 8
Servo2 = 21
Servo3 = 18
Servo4 = 11
MotorPos = 24
MotorNeg = 25
Limiter = 16
LCD_Pin = 15
LCD_Baud = 19_200
LCD_Lines = 2
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
OBJ
servo: "Servo32v5.spin"
PST: "Parallax seriell Terminal"
LCD: "debug_lcd"
VAR
byte smak
byte skott
PUB huvudsakliga
servo.start
servo.set (Servo1, 1350)
servo.set (Servo2, 570)
servo.set (Servo3, 980)
servo.set (Servo4, 1000)
LCD.init (LCD_Pin, LCD_Baud, LCD_Lines)
LCD.cursor(0)
LCD.cls
LCD.gotoxy(0,0)
LCD.cls
LCD.str (sträng ("Espresso magi", 13, "Av Roy Eid", 13))
waitcnt (clkfreq * 2 + cnt)
Dira [MotorPos] ~ ~
Dira [MotorNeg] ~ ~
Smak: = 0
Skott: = 0
flava
PUB shat
Upprepa
om ina [Shot2] == 1
LCD.gotoxy (9, 1)
LCD.str(string("2"))
Skott: = 1
Commander
om ina [Shot4] == 1
LCD.gotoxy (9, 1)
LCD.str(string("4"))
Skott: = 2
Commander
om ina [Avbryt] == 1
LCD.cls
LCD.str (sträng ("Annullerad av", 13, "användare"))
waitcnt (clkfreq + cnt)
flava
PUB flava
LCD.cls
LCD.str (sträng ("smak:", 13, "skott :"))
Upprepa
om ina [Flavor1] == 1
LCD.gotoxy (9, 0)
LCD.str(string("1"))
Smak: = 1
Shat
om ina [Flavor2] == 1
LCD.gotoxy (9, 0)
LCD.str(string("2"))
Smak: = 2
Shat
om ina [Flavor3] == 1
LCD.gotoxy (9, 0)
LCD.str(string("3"))
Smak: = 3
Shat
PUB commander
Upprepa
om ina [Start] == 1
LCD.cls
LCD.str(string("Dispensing..."))
avstå från
om ina [Avbryt] == 1
LCD.cls
LCD.str (sträng ("Annullerad av", 13, "användare"))
waitcnt (clkfreq + cnt)
flava
PUB avstå från
servo.set (Servo4, 1600)
waitcnt (clkfreq * 1 + cnt)
fallet smak
1:
servo.set (Servo1, 1800)
om skott == 1
waitcnt (clkfreq * 2 + cnt)
servo.set (Servo1, 1350)
waitcnt (clkfreq * 1 + cnt)
kompakt
om skott == 2
waitcnt (clkfreq * 4 + cnt)
servo.set (Servo1, 1350)
waitcnt (clkfreq * 1 + cnt)
kompakt
2:
servo.set (Servo2, 1000)
om skott == 1
waitcnt (clkfreq * 2 + cnt)
servo.set (Servo2, 570)
waitcnt (clkfreq * 1 + cnt)
kompakt
om skott == 2
waitcnt (clkfreq * 4 + cnt)
servo.set (Servo2, 570)
waitcnt (clkfreq * 1 + cnt)
kompakt
3:
servo.set (Servo3, 550)
om skott == 1
waitcnt (clkfreq * 2 + cnt)
servo.set (Servo3, 980)
waitcnt (clkfreq * 1 + cnt)
kompakt
om skott == 2
waitcnt (clkfreq * 4 + cnt)
servo.set (Servo3, 980)
waitcnt (clkfreq * 1 + cnt)
kompakt
PUB kompakt
servo.set (Servo4, 1000)
waitcnt (clkfreq * 2 + cnt)
Upprepa 2
om ina [Limiter] == 0
upp
om ina [Limiter] == 1
ned
upp
LCD.cls
LCD.str(string("done!"))
waitcnt (clkfreq * 2 + cnt)
flava
PUB upp
Upprepa
LCD.gotoxy(0,0)
LCD.str(string("Compacting..."))
Outa [MotorNeg]: = 1
Outa [MotorPos]: = 0
om ina [Limiter] == 1
Outa [MotorNeg]: = 0
Outa [MotorPos]: = 0
avsluta
PUB ner
LCD.cls
LCD.str(string("Compacting..."))
Upprepa 100
Outa [MotorPos]: = 1
Outa [MotorNeg]: = 0
waitcnt (clkfreq/500 + cnt)
Outa [MotorNeg]: = 0
Outa [MotorPos]: = 0
waitcnt (clkfreq/500 + cnt)