Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SoftwareSerial.h>
- const int led=9, rxPin=8, txPin=7;
- int lum; //Il valore letto dalla fotoresistenza
- char tmp=0;
- SoftwareSerial bt(rxPin,txPin);
- void setup() {
- Serial.begin(9600);
- bt.begin(38400);
- pinMode(led,OUTPUT);
- }
- void loop() {
- if(bt.available()){
- tmp=bt.read();
- Serial.println(tmp);
- switch (tmp){
- case 'A':
- autof();
- break;
- case 'H' :
- highf();
- break;
- case 'L':
- lowf();
- break;
- }
- }
- }
- void autof(){
- lum = analogRead(A0); //Lettura della luminosità
- lum = lum/4; //Adeguiamo il valore della luminosità
- analogWrite(led,lum); //Mettiamo il valore letto per il led
- delay(10); //Aspetta 10 ms
- }
- void highf(){
- digitalWrite(led,);
- }
- void lowf(){
- digitalWrite(led,LOW);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement