Progetto

Generale

Profilo

File » TB_Music_Dance_02.01.2016.ino

Moreno Petrucci, 03-01-2016 00:43

 
1
#include <IRremote.h>
2

    
3
int RECV_PIN = 11;
4

    
5
IRrecv irrecv(RECV_PIN);
6
decode_results results;
7

    
8
// RGB Led Control
9
const int yellowLEDPin = 10;    // LED connected to digital pin 9
10
const int redLEDPin = 9;     // LED connected to digital pin 8
11
const int blueLEDPin = 8; 
12

    
13
boolean ch_free; // Canale libero o occupato
14

    
15
void setup() {
16
  
17
  irrecv.enableIRIn(); // Start the receiver
18
  
19
  pinMode(6, OUTPUT); // Motor 2
20
  pinMode(5, OUTPUT); // Motor 1
21
  pinMode(13, OUTPUT); //Led (opzionale)
22
  
23
  // pin RGB Led
24
  pinMode(yellowLEDPin,OUTPUT);
25
  pinMode(redLEDPin,OUTPUT);
26
  pinMode(blueLEDPin,OUTPUT);
27
  
28
  //randomSeed(85); 
29

    
30
}
31

    
32
void loop() {
33
  
34
  ascolto_canale();
35
  
36
}
37

    
38
void ascolto_canale() {
39

    
40
    // Se il canale è libero -> LED Verde altrimenti ROSSO
41
  if (ch_free) {
42
      digitalWrite(redLEDPin, LOW);
43
      digitalWrite(yellowLEDPin, HIGH);
44
      digitalWrite(blueLEDPin, HIGH);
45
      //Stop motori
46
      analogWrite(6, 0);
47
      analogWrite(5, 0);
48
  } else {
49
      digitalWrite(redLEDPin, LOW);
50
      digitalWrite(yellowLEDPin, HIGH);
51
      digitalWrite(blueLEDPin, HIGH);
52
  }
53
  
54
     // Ricezione dati IR
55
    if (irrecv.decode(&results)) {
56
    
57
      ch_free = false;
58
      
59
      // Led diventa rosso quando si ricevono dati
60
//      digitalWrite(redLEDPin, HIGH);
61
//      digitalWrite(yellowLEDPin, LOW);
62
//      digitalWrite(blueLEDPin, LOW);
63

    
64
      digitalWrite(redLEDPin, HIGH);
65
      digitalWrite(yellowLEDPin, LOW);
66
      digitalWrite(blueLEDPin, LOW);
67
//      Serial.println(results.value, DEC);
68
                // Controllo il valore esadecimale in ricezione
69
          switch(results.value) {
70
            case (0x12A):
71
                      analogWrite(6, random(90,130));
72
                      analogWrite(5, random(90,130));
73
                      
74
            break;
75
            case (0x12B):
76
                      analogWrite(6, random(130,180));
77
                      analogWrite(5, random(130,180));
78
            break;
79
            case (0x12C):
80
                      analogWrite(6, random(180,250));
81
                      analogWrite(5, random(180,250));
82
            break;
83
          
84
          }
85
      irrecv.resume();
86
    }
87
    delay(100);
88
    ch_free = true;
89
}
(4-4/5)