akuygry
Dependencies: mbed Servo KeypadLib TextLCD
Cassaforte.cpp@0:5f8790dfc90c, 2018-12-04 (annotated)
- Committer:
- Virgi97
- Date:
- Tue Dec 04 10:11:08 2018 +0000
- Revision:
- 0:5f8790dfc90c
- Child:
- 1:02c938489de7
Cassciaforte
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Virgi97 | 0:5f8790dfc90c | 1 | #include "Cassaforte.h" |
Virgi97 | 0:5f8790dfc90c | 2 | #include "TextLCD.h" |
Virgi97 | 0:5f8790dfc90c | 3 | #include "Servo.h" |
Virgi97 | 0:5f8790dfc90c | 4 | I2C i2c(D14, D15); |
Virgi97 | 0:5f8790dfc90c | 5 | //InterruptIn button(PC_13); |
Virgi97 | 0:5f8790dfc90c | 6 | TextLCD_I2C lcd(&i2c, 0x4E, TextLCD_I2C::LCD16x2, TextLCD_I2C::HD44780); |
Virgi97 | 0:5f8790dfc90c | 7 | DigitalOut led(LED1); |
Virgi97 | 0:5f8790dfc90c | 8 | Servo servo(D3); |
Virgi97 | 0:5f8790dfc90c | 9 | bool sensore = false; |
Virgi97 | 0:5f8790dfc90c | 10 | |
Virgi97 | 0:5f8790dfc90c | 11 | void inizializza(){ |
Virgi97 | 0:5f8790dfc90c | 12 | lcd.setMode(TextLCD_I2C::DispOn); |
Virgi97 | 0:5f8790dfc90c | 13 | lcd.setCursor(TextLCD_I2C::CurOn_BlkOn); |
Virgi97 | 0:5f8790dfc90c | 14 | if (sensore == true) |
Virgi97 | 0:5f8790dfc90c | 15 | chiuso(); |
Virgi97 | 0:5f8790dfc90c | 16 | else aperto(); |
Virgi97 | 0:5f8790dfc90c | 17 | } |
Virgi97 | 0:5f8790dfc90c | 18 | |
Virgi97 | 0:5f8790dfc90c | 19 | void scrivi(char parola[]){ |
Virgi97 | 0:5f8790dfc90c | 20 | lcd.cls(); |
Virgi97 | 0:5f8790dfc90c | 21 | lcd.printf("%s\n", parola); |
Virgi97 | 0:5f8790dfc90c | 22 | } |
Virgi97 | 0:5f8790dfc90c | 23 | |
Virgi97 | 0:5f8790dfc90c | 24 | void cambioCodice(){ |
Virgi97 | 0:5f8790dfc90c | 25 | led=!led; |
Virgi97 | 0:5f8790dfc90c | 26 | scrivi("Cambio codice di apertura"); |
Virgi97 | 0:5f8790dfc90c | 27 | lcd.setAddress(11,1); |
Virgi97 | 0:5f8790dfc90c | 28 | wait(3); |
Virgi97 | 0:5f8790dfc90c | 29 | lcd.cls(); |
Virgi97 | 0:5f8790dfc90c | 30 | scrivi("Digitare il nuo_vo codice:"); |
Virgi97 | 0:5f8790dfc90c | 31 | lcd.setAddress(10,1); |
Virgi97 | 0:5f8790dfc90c | 32 | inserimento(); |
Virgi97 | 0:5f8790dfc90c | 33 | led=!led; |
Virgi97 | 0:5f8790dfc90c | 34 | } |
Virgi97 | 0:5f8790dfc90c | 35 | |
Virgi97 | 0:5f8790dfc90c | 36 | void inserimento(){ |
Virgi97 | 0:5f8790dfc90c | 37 | /*for (int i=0; i<4; i++){ |
Virgi97 | 0:5f8790dfc90c | 38 | wait(1); |
Virgi97 | 0:5f8790dfc90c | 39 | lcd.putc(i); |
Virgi97 | 0:5f8790dfc90c | 40 | wait(1); |
Virgi97 | 0:5f8790dfc90c | 41 | lcd.setAddress(11+i,1); |
Virgi97 | 0:5f8790dfc90c | 42 | }*/ |
Virgi97 | 0:5f8790dfc90c | 43 | wait(1); |
Virgi97 | 0:5f8790dfc90c | 44 | lcd.putc('1'); |
Virgi97 | 0:5f8790dfc90c | 45 | wait(1); |
Virgi97 | 0:5f8790dfc90c | 46 | lcd.setAddress(11,1); |
Virgi97 | 0:5f8790dfc90c | 47 | lcd.putc('2'); |
Virgi97 | 0:5f8790dfc90c | 48 | wait(1); |
Virgi97 | 0:5f8790dfc90c | 49 | lcd.setAddress(12,1); |
Virgi97 | 0:5f8790dfc90c | 50 | lcd.putc('3'); |
Virgi97 | 0:5f8790dfc90c | 51 | wait(1); |
Virgi97 | 0:5f8790dfc90c | 52 | lcd.setAddress(13,1); |
Virgi97 | 0:5f8790dfc90c | 53 | lcd.putc('4'); |
Virgi97 | 0:5f8790dfc90c | 54 | wait(1); |
Virgi97 | 0:5f8790dfc90c | 55 | } |
Virgi97 | 0:5f8790dfc90c | 56 | |
Virgi97 | 0:5f8790dfc90c | 57 | void chiuso(){ |
Virgi97 | 0:5f8790dfc90c | 58 | servo.position(-90); |
Virgi97 | 0:5f8790dfc90c | 59 | |
Virgi97 | 0:5f8790dfc90c | 60 | } |
Virgi97 | 0:5f8790dfc90c | 61 | |
Virgi97 | 0:5f8790dfc90c | 62 | void aperto(){ |
Virgi97 | 0:5f8790dfc90c | 63 | servo.position(-90); |
Virgi97 | 0:5f8790dfc90c | 64 | |
Virgi97 | 0:5f8790dfc90c | 65 | } |