Stap 7: SPIN Code
SPIN CodeCON
Flavor1 = 0
Flavor2 = 1
Flavor3 = 2
Shot2 = 3
Shot4 = 4
Start = 5
Annuleren = 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 seriële Terminal"
LCD: "debug_lcd"
VAR
byte smaak
byte Shot
Belangrijkste PUB
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 (string ("Espresso Magic", 13, "Door Roy Eid" 13))
waitcnt (clkfreq * 2 + cnt)
Dira [MotorPos] ~ ~
Dira [MotorNeg] ~ ~
Smaak: = 0
Schot: = 0
flava
PUB shat
Herhaal
Als ina [Shot2] == 1
LCD.gotoxy (9, 1)
LCD.str(string("2"))
Schot: = 1
commandant
Als ina [Shot4] == 1
LCD.gotoxy (9, 1)
LCD.str(string("4"))
Schot: = 2
commandant
Als ina [Annuleren] == 1
LCD.cls
LCD.str (string ("Geannuleerd door", 13, "gebruiker"))
waitcnt (clkfreq + cnt)
flava
PUB flava
LCD.cls
LCD.str (string ("smaak:", 13, "Shots :"))
Herhaal
Als ina [Flavor1] == 1
LCD.gotoxy (9, 0)
LCD.str(string("1"))
Smaak: = 1
Shat
Als ina [Flavor2] == 1
LCD.gotoxy (9, 0)
LCD.str(string("2"))
Smaak: = 2
Shat
Als ina [Flavor3] == 1
LCD.gotoxy (9, 0)
LCD.str(string("3"))
Smaak: = 3
Shat
Commandant van de PUB
Herhaal
Als ina [Start] == 1
LCD.cls
LCD.str(string("Dispensing..."))
afzien
Als ina [Annuleren] == 1
LCD.cls
LCD.str (string ("Geannuleerd door", 13, "gebruiker"))
waitcnt (clkfreq + cnt)
flava
PUB afzien
Servo.set (Servo4, 1600)
waitcnt (clkfreq * 1 + cnt)
geval van smaak
1:
Servo.set (Servo1, 1800)
als schot == 1
waitcnt (clkfreq * 2 + cnt)
Servo.set (Servo1, 1350)
waitcnt (clkfreq * 1 + cnt)
Compact
als schot == 2
waitcnt (clkfreq * 4 + cnt)
Servo.set (Servo1, 1350)
waitcnt (clkfreq * 1 + cnt)
Compact
2:
Servo.set (Servo2, 1000)
als schot == 1
waitcnt (clkfreq * 2 + cnt)
Servo.set (Servo2, 570)
waitcnt (clkfreq * 1 + cnt)
Compact
als schot == 2
waitcnt (clkfreq * 4 + cnt)
Servo.set (Servo2, 570)
waitcnt (clkfreq * 1 + cnt)
Compact
3:
Servo.set (Servo3, 550)
als schot == 1
waitcnt (clkfreq * 2 + cnt)
Servo.set (Servo3, 980)
waitcnt (clkfreq * 1 + cnt)
Compact
als schot == 2
waitcnt (clkfreq * 4 + cnt)
Servo.set (Servo3, 980)
waitcnt (clkfreq * 1 + cnt)
Compact
PUB compact
Servo.set (Servo4, 1000)
waitcnt (clkfreq * 2 + cnt)
Herhaal 2
Als ina [Limiter] == 0
omhoog
Als ina [Limiter] == 1
naar beneden
omhoog
LCD.cls
LCD.str(string("done!"))
waitcnt (clkfreq * 2 + cnt)
flava
PUB omhoog
Herhaal
LCD.gotoxy(0,0)
LCD.str(string("Compacting..."))
outa [MotorNeg]: = 1
outa [MotorPos]: = 0
Als ina [Limiter] == 1
outa [MotorNeg]: = 0
outa [MotorPos]: = 0
sluit af
PUB naar beneden
LCD.cls
LCD.str(string("Compacting..."))
Herhaal 100
outa [MotorPos]: = 1
outa [MotorNeg]: = 0
waitcnt (clkfreq/500 + cnt)
outa [MotorNeg]: = 0
outa [MotorPos]: = 0
waitcnt (clkfreq/500 + cnt)