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: BME280 MFRC522 mbed
Diff: main.cpp
- Revision:
- 1:9c4b2fdf3b67
- Parent:
- 0:91215b8406ee
- Child:
- 2:3dd81ff9eb1f
--- a/main.cpp Fri Jun 15 22:09:12 2018 +0000
+++ b/main.cpp Sat Jun 23 20:42:10 2018 +0000
@@ -21,24 +21,97 @@
// Declaração para utilização do RFID
MFRC522 RFID(p11, p12, p13, p14, p8);
+// Variável de verificação de autenticação
+int autenticado = 0;
+
+// Variável de entrada bluetooth
+char input;
+
+
+
+// Função de exibição dos sensores
+void exibirInfo()
+{
+ int aux = 1;
+ char sair;
+ bluetooth.printf("Exibindo informacoes. 'S' para sair.");
+ while (aux) {
+ bluetooth.readable();
+ sair = bluetooth.getc();
+ bluetooth.printf("%2.2f C, %04.2f hPa\nUmidade: %3.3f%%", sensor_t_p.getTemperature(), sensor_t_p.getPressure(), (1-sensor_u.read()) * 100.0f);
+ }
+}
+
+
+
+int main()
+{
+ bomba.period_ms(10);
+ bluetooth.baud(9600);
+ RFID.PCD_Init();
+
+ bluetooth.printf("Bem vindo ao sistema de controle da estufa.\nPara acessar as configuracoes, identifique-se pelo cracha RFID.\n\n");
-// Código PWM da bomba (realocar)
- bomba.period_ms(10);
- bomba.write(0.5f);
+ while(1) {
+
+ // Programa a ser executado caso esteja autenticado
+ if (autenticado) {
+ bluetooth.printf("\n\n\nSelecione a operacao desejada:\n");
+ bluetooth.printf("\t(I)nformacoes de Pressao, Temperatura e Umidade\n");
+ bluetooth.printf("\t(L)igar a Bomba\n");
+ bluetooth.printf("\t(D)esligar a Bomba\n");
+ bluetooth.printf("\t(S)air\n");
-
+ if (bluetooth.readable()) {
+//NAO TA ENTRANDO
+ while (autenticado) {
+ bluetooth.printf("ENTREI\n\n");
+ input = bluetooth.getc();
+
+ switch (input) {
+ case 'I':
+ exibirInfo();
+ break;
+
+ case 'L':
+ bomba.write(0.5f);
+ break;
+
+
+ case 'D':
+ bomba.write(0.0f);
+ break;
-int main() {
-
- bluetooth.baud(9600);
-
- while(1) {
- bluetooth.printf("%2.2f Cº, %04.2f hPa\n", sensor_t_p.getTemperature(), sensor_t_p.getPressure());
- bluetooth.printf("Valor Absoluto (umidade): %2.3f", 1-sensor.read());
- wait(1);
-
-
-
+ case 'S':
+ autenticado = 0;
+ break;
+ }
+ }
+ }
+ }
+
+ // Procura o card
+ if ( ! RFID.PICC_IsNewCardPresent()) {
+ wait_ms(500);
+ continue;
+ }
+
+ // Seleciona um dos cards
+ if ( ! RFID.PICC_ReadCardSerial()) {
+ wait_ms(500);
+ continue;
+ }
+
+ autenticado = 1;
+
+ bluetooth.printf("Card reconhecido, acesso concedido.\n\n");
+
+ // Imprime Card UID
+ bluetooth.printf("Card UID: ");
+ for (uint8_t i = 0; i < RFID.uid.size; i++) {
+ bluetooth.printf(" %X02", RFID.uid.uidByte[i]);
+ }
+ bluetooth.printf("\n\n---------------------------------------------------------------------------");
}
}