Olá pessoal hoje ensinarei vocês como usar o Arduíno para acender LEDs
via Bluetooth, para este tutorial, não precisaremos de nenhuma biblioteca, pois
o mesmo e tratado como serial.
Este e um projeto relativamente simples, bem fácil de montar.
Para este tutorial precisaremos de:
Você encontra estes e outros componentes na loja
Sttamp.com
As variáveis dos botões são:
Botão 1 = '1';
Botão 2 = '2';
Botão 3 = '3';
Botão 4 = '4';
Código:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Mais tutoriais em http://blog.sttamp.com/ | |
grupo no whatsApp "Viciados em Arduino" des de 27/04/2014 | |
WhatsAppp +55 66 9667-0801 | |
*/ | |
int led1 = 2; | |
int led2 = 3; | |
int led3 = 4; | |
int led4 = 5; | |
int estado1 = LOW; | |
int estado2 = LOW; | |
int estado3 = LOW; | |
int estado4 = LOW; | |
char leitura; | |
void setup(){ | |
Serial.begin(9600); | |
pinMode(led1, OUTPUT); | |
pinMode(led2, OUTPUT); | |
pinMode(led3, OUTPUT); | |
pinMode(led4, OUTPUT); | |
} | |
void loop(){ | |
if(Serial.available()){ | |
leitura = Serial.read(); | |
Serial.print(leitura); | |
if(leitura == '1'){ | |
estado1 = !estado1; | |
} | |
if(leitura == '2'){ | |
estado2 = !estado2; | |
} | |
if(leitura == '3'){ | |
estado3 = !estado3; | |
} | |
if(leitura == '4'){ | |
estado4 = !estado4; | |
} | |
} | |
digitalWrite(led1, estado1); | |
digitalWrite(led2, estado2); | |
digitalWrite(led3, estado3); | |
digitalWrite(led4, estado4); | |
} |
Nenhum comentário:
Postar um comentário