Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.84 KB | None | 0 0
  1. #include <SoftwareSerial.h>
  2. const int led=9, rxPin=8, txPin=7;
  3. int lum;  //Il valore letto dalla fotoresistenza
  4. char tmp=0;
  5.  
  6. SoftwareSerial bt(rxPin,txPin);
  7.  
  8. void setup() {
  9.   Serial.begin(9600);
  10.   bt.begin(38400);
  11.   pinMode(led,OUTPUT);
  12. }
  13.  
  14. void loop() {
  15.  
  16.   if(bt.available()){
  17.     tmp=bt.read();
  18.     Serial.println(tmp);
  19.     switch (tmp){
  20.       case 'A':
  21.         autof();
  22.       break;
  23.       case 'H' :
  24.         highf();
  25.       break;
  26.       case 'L':
  27.         lowf();
  28.       break;
  29.      
  30.     }
  31.   }
  32. }
  33.  
  34.  
  35.  
  36. void autof(){
  37.     lum = analogRead(A0);  //Lettura della luminosità
  38.     lum = lum/4;  //Adeguiamo il valore della luminosità
  39.     analogWrite(led,lum);  //Mettiamo il valore letto per il led
  40.     delay(10);  //Aspetta 10 ms
  41.   }
  42.  
  43. void highf(){
  44.   digitalWrite(led,);  
  45. }
  46.  
  47. void lowf(){
  48.   digitalWrite(led,LOW);
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement