Progetto

Generale

Profilo

File » TB_Music_Dance_02.01.2016_v2.ino

Moreno Petrucci, 06-01-2016 13:31

 
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

    
61
//      digitalWrite(redLEDPin, HIGH);
62
//      digitalWrite(yellowLEDPin, LOW);
63
//      digitalWrite(blueLEDPin, LOW);
64
      
65

    
66
//      Serial.println(results.value, DEC);
67
                // Controllo il valore esadecimale in ricezione
68
          switch(results.value) {
69
            case (0x12A):
70
                      analogWrite(6, random(90,130));
71
                      analogWrite(5, random(90,130));
72
                      
73
                      analogWrite(redLEDPin, 40);
74
                      analogWrite(yellowLEDPin, 95);
75
                      analogWrite(blueLEDPin, 0);
76
                      
77
            break;
78
            case (0x12B):
79
                      analogWrite(6, random(130,180));
80
                      analogWrite(5, random(130,180));
81
                      
82
                      analogWrite(redLEDPin, 185);
83
                      analogWrite(yellowLEDPin, 0);
84
                      analogWrite(blueLEDPin, 185);
85
            break;
86
            case (0x12C):
87
                      analogWrite(6, random(180,250));
88
                      analogWrite(5, random(180,250));
89
                      
90
                      analogWrite(redLEDPin, 255);
91
                      analogWrite(yellowLEDPin, 0);
92
                      analogWrite(blueLEDPin, 0);
93
            break;
94
          
95
          }
96
      irrecv.resume();
97
    }
98
    delay(100);
99
    ch_free = true;
100
}
(5-5/5)