Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed Servo KeypadLib TextLCD
Revision 1:0661b733846e, committed 2018-12-09
- Comitter:
- Virgi97
- Date:
- Sun Dec 09 22:01:57 2018 +0000
- Parent:
- 0:376d7a150177
- Child:
- 2:ca52e00afb99
- Commit message:
- Il codice implementa il buzzer attivo monotonale
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Cassaforte.cpp Sun Dec 09 22:01:57 2018 +0000
@@ -0,0 +1,184 @@
+#include "Cassaforte.h"
+#include "TextLCD.h"
+#include "Servo.h"
+#include "keypad.h"
+I2C i2c(D14, D15);
+TextLCD_I2C lcd(&i2c, 0x4E, TextLCD_I2C::LCD16x2, TextLCD_I2C::HD44780); //comunicazione Nucleo-display
+Keypad keypad(D6,D5,D4,D3,D10,D9,D8,D7); //porte del tastierino
+Servo servo(D11); //porta servo
+//PwmOut buzzer(D2);
+//Ticker t;
+Timeout t1;
+DigitalOut led_verde(D13); //led apertura
+DigitalOut led_rosso(D12); //led chiusura
+DigitalOut buz(D2); //porta buz
+DigitalIn mag(PC_13); //porta del magnete
+int dim=4;
+//int buz=0;
+char pass[4]={'1','2','3','4'};//password di default (è possibile cambiarla dal menu)
+bool alonoff=true; //variabile booleana per abilitare o disabilitare l'allarme in caso di apertura e chiusura (?)
+bool jump = false;
+
+void inizializza(){
+ lcd.setMode(TextLCD_I2C::DispOn);
+ lcd.setBacklight(TextLCD_I2C::LightOff);
+ buz=0;
+
+ if(mag == 1){
+ chiuso();
+ //wait(0.3);
+ } else aperto();
+ //lcd.setCursor(TextLCD_I2C::CurOn_BlkOn);
+ }
+
+void scrivi(char parola[]){
+ lcd.cls();
+ lcd.printf("%s\n", parola);
+ }
+
+void chiuso(){
+ servo.position(90);
+ wait(0.3);
+ led_rosso = 1;
+ led_verde = 0;
+ }
+
+void aperto(){
+ servo.position(-90);
+ wait(0.3);
+ led_rosso = 0;
+ led_verde = 1;
+ }
+void inserimento(char a[],int n,bool vis){
+ int i=0;
+ jump = false;
+ /*Timer t;
+ t.reset();
+ t.start();*/
+ t1.attach(&salta, 20);
+ do{
+ keypad.enablePullUp();
+ char val = keypad.getKey();
+ if(/*t.read()>20*/jump == true && buz==0){ //CHIUSURA dopo 20 secondi dal mancato inserimento
+ main();
+ }
+ if(val != KEY_RELEASED){
+ if(vis==true){
+ lcd.putc(val);
+ lcd.setAddress(i+1,1);
+ }
+ a[i]=val;
+ i++;
+ wait(0.4);
+
+ }
+ }while(i<n);
+
+}
+
+bool confronto(char v[],int dim){
+ int cont=0;
+ for(int i=0;i<dim;i++){
+ if (v[i]==pass[i]){
+ cont++;
+ }
+ }
+ if (cont==4){
+ return true;
+ }
+ else{
+ return false;
+ }
+}
+
+void menu(){
+ scrivi("A Apri B BloccaC Cambia codice");
+ char val;
+ do{
+ inserimento(&val,1,false);
+
+ }while(val!='A' && val!='B' && val!='C');
+
+ if(val=='A'){
+ //if(mag==1){
+ scrivi("Apertura...");
+ alonoff=false;
+ aperto();
+ wait(0.3); //2
+ menu();
+ // }
+ }
+ if(val=='B'){
+ if(mag==0){
+ scrivi("Chiusura...");
+ alonoff=true;
+ chiuso();
+ wait(0.3); //2
+ main();
+ }
+ }
+ if(val=='C'){
+ char v[dim];
+ scrivi("Nuovo codice:");
+ inserimento(v,dim,true);
+ scrivi("Codice: ");
+ for(int i=0;i<4;i++){
+ lcd.setAddress(i+12,0);
+ lcd.putc(v[i]);
+ }
+ lcd.printf("A:ok C:annulla");
+ do{
+ inserimento(&val,1,false);
+ if(val=='A'){
+ scrivi("Codice cambiato.");
+ wait(1);
+ for(int k=0;k<dim;k++){
+ pass[k]=v[k];
+ }
+ main();
+ }
+ if(val=='C'){
+ menu();
+ }
+
+ }while(1);
+ }
+}
+
+void allarme(){
+ bool esci = true;
+ char insa[4];
+ //t.attach(&suona, 1);
+ do{
+ buz=1;
+ scrivi(" Allarme!");
+ inserimento(insa,4,true);
+
+
+ if(confronto(insa,4)==true){
+ buz=0;
+ esci = false;
+ //t.detach;
+ }
+ }while(esci);
+ //scrivi("Attendere...");
+ t1.attach(&salta, 0.5);
+}
+
+void controllo(){
+ if (alonoff == true){
+ allarme();
+ }
+ }
+
+/*void suona (float freq1, float freq2, float t1, float t2 float v[]){
+ buzzer.period_ms(3);
+ buzzer.write(0.1);
+ wait(0.5);
+ buzzer.write(0.5);
+ wait(0.5);
+ }*/
+
+void salta(){
+ jump = true;
+ }
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Cassaforte.h Sun Dec 09 22:01:57 2018 +0000 @@ -0,0 +1,16 @@ +#ifndef Cassaforte_H +#define Cassaforte_H +#include "mbed.h" +int main(); +void inizializza(); +void scrivi(char parola[]); +void inserimento(char[],int,bool); +bool confronto(char[],int); +void chiuso(); +void aperto(); +void menu(); +void allarme(); +void controllo(); +void suona(/*float, float, float, float*/); +void salta(); +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/KeypadLib.lib Sun Dec 09 22:01:57 2018 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/rlanghbv/code/KeypadLib/#fb28bc08ded4
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Servo.lib Sun Dec 09 22:01:57 2018 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/simon/code/Servo/#36b69a7ced07
--- a/TextLCD.lib Wed Dec 03 03:48:48 2014 +0000 +++ b/TextLCD.lib Sun Dec 09 22:01:57 2018 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/users/oscarvzfz/code/TextLCD/#d824a83e56e3 +https://os.mbed.com/users/foreste/code/TextLCD/#fa02cddf2fd8
--- a/main.cpp Wed Dec 03 03:48:48 2014 +0000
+++ b/main.cpp Sun Dec 09 22:01:57 2018 +0000
@@ -1,20 +1,89 @@
-#include "mbed.h"
-#include "TextLCD.h"
-//Incluye resistencias de 2.2K en los pines de i2c a 3.3
-
-
+/* *PINOUT E CABLAGGIO
+ *5V ---> VCC MODULO I2C DISPLAY;
+ *GND ---> VCC MODULO I2C DISPLAY, CATODI LED, BUZZER-PIEZO;
+ *PIN D15 ---> SCL MODULO I2C DISPLAY;
+ *PIN D14 ---> SDA MODULO I2C DISPLAY;
+ *PIN D13 ---> LED VERDE;
+ *PIN D12 ---> LED ROSSO;
+ *PIN D11 ---> SERVO;
+ *PIN D10 ---> PIN 1 TASTIERINO;
+ *PIN D9 ---> PIN 2 TASTIERINO;
+ *PIN D8 ---> PIN 3 TASTIERINO;
+ *PIN D7 ---> PIN 4 TASTIERINO;
+ *PIN D6 ---> PIN 5 TASTIERINO;
+ *PIN D5 ---> PIN 6 TASTIERINO;
+ *PIN D4 ---> PIN 7 TASTIERINO;
+ *PIN D3 ---> PIN 8 TASTIERINO;
+ *PIN D2 ---> BUZZER-PIEZO;
+ *PIN PC_10 ---> INTERRUTTORE MAGNETICO;
+
+*/
-// I2C Communication
-I2C i2c_lcd(p28,p27); // SDA, SCL
-
-TextLCD_I2C lcd(&i2c_lcd, 0x4E, TextLCD::LCD16x2, TextLCD::HD44780); // I2C bus, PCF8574 Slaveaddress, LCD Type, Device Type
-
+#include "Cassaforte.h"
+#include "mbed.h"
+//#include <TextLCD.h>
+//I2C i2c(D14, D15);
+//TextLCD_I2C lcd(&i2c, 0x4E, TextLCD_I2C::LCD16x2, TextLCD_I2C::HD44780);
+/*DigitalOut led(LED1);
+void scrivi(char parola[]);
+void cambioCodice();
+void inserisci();*/
+InterruptIn alarm(PC_13);
+bool avvio = true;
+char v[4];
+int cont2;
+int main() {
+ alarm.rise(&controllo);
+ if (avvio == true){
+ inizializza();
+ avvio = false;
+ }
+ cont2=0;
+ do{
+ scrivi("Immetti codice:");
+ inserimento(v,4,true);
+ if (confronto(v,4)==true){
+ menu();
+ }
+ else{
+ scrivi("Codice errato");
+ wait(0.8);
+ cont2++;
+ }
+ }while(cont2<3);
+
+ if (cont2==3){
+ allarme();
+ }
+
+}
-int main()
-{
-lcd.setMode(TextLCD::DispOn); //DispOff, DispOn
-lcd.setBacklight(TextLCD::LightOff);//LightOff, LightOn
-lcd.setCursor(TextLCD::CurOff_BlkOff);//CurOff_BlkOff, CurOn_BlkOff, CurOff_BlkOn, CurOn_BlkOn
-lcd.printf("Oscar de Jesus \n Vasquez");
-
- }
\ No newline at end of file
+/*void scrivi(char parola[]){
+ lcd.cls();
+ lcd.printf("%s\n", parola);
+ }
+
+void cambioCodice(){
+ scrivi("Cambio codice di apertura");
+ lcd.setAddress(11,1);
+ wait(3);
+ lcd.cls();
+ scrivi("Digitare il nuo_ vo codice:");
+ lcd.setAddress(10,1);
+ inserisci();
+ }
+
+void inserisci(){
+ wait(1);
+ lcd.putc('1');
+ wait(1);
+ lcd.setAddress(11,1);
+ lcd.putc('2');
+ wait(1);
+ lcd.setAddress(12,1);
+ lcd.putc('3');
+ wait(1);
+ lcd.setAddress(13,1);
+ lcd.putc('4');
+ wait(1);
+ }*/
\ No newline at end of file