Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* +-----+
- +----[PWR]-------------------| USB |--+
- | +-----+ |
- | GND/RST2 [ ][ ] |
- | MOSI2/SCK2 [ ][ ] A5/SCL[ ] |
- | 5V/MISO2 [ ][ ] A4/SDA[ ] |
- | AREF[ ] |
- | GND[ ] |
- | [ ]N/C SCK/13[ ] |
- | [ ]IOREF MISO/12[ ] |
- | [ ]RST MOSI/11[ ]~|
- | [ ]3V3 +---+ 10[ ]~|
- | [ ]5v -| A |- 9[ ]~|
- | [ ]GND -| R |- 8[ ] | LED
- | [ ]GND -| D |- | +--------|>|----RRRRR---GND
- | [ ]Vin -| U |- 7[ ] | |
- | -| I |- 6[ ]~| |
- | [ ]A0 -| N |- 5[ ]~|------+ +----+
- | [ ]A1 -| O |- 4[ ] |------------| IR |
- | [ ]A2 +---+ INT1/3[ ]~| +----+
- | [ ]A3 INT0/2[ ] |
- | [ ]A4/SDA RST SCK MISO TX>1[ ] |
- | [ ]A5/SCL [ ] [ ] [ ] RX<0[ ] |
- | [ ] [ ] [ ] |
- | UNO_R3 GND MOSI 5V ____________/
- \_______________________/
- */
- #include <IRremote.h>
- int RECV_PIN = 4;
- IRrecv irrecv(RECV_PIN);
- decode_results results;
- int redPin = 12; //rgb led
- int greenPin = 8;
- int bluePin = 7;
- int const potenciometro = 0; //motor pot
- int const transTIP120 = 10;
- int valPotenciometro = 0;
- int i1 = 0;
- int i2 = 0;
- int i3 = 0;
- int i4 = 0;
- int i5 = 0;
- int i6 = 0;
- int i7 = 0;
- int i8 = 0;
- int i9 = 0;
- int led = 5; //leds
- int brightness = 0;
- int fadeAmount = 5;
- //------------------------------
- void setup()
- {
- Serial.begin(9600);
- pinMode(transTIP120, OUTPUT); //pot motor
- irrecv.enableIRIn();
- pinMode(led, OUTPUT); //leds
- pinMode(redPin, OUTPUT); //rgb
- pinMode(greenPin, OUTPUT);
- pinMode(bluePin, OUTPUT);
- pinMode(2, OUTPUT); //RELAY
- pinMode(3, OUTPUT);
- pinMode(5, OUTPUT);
- pinMode(6, OUTPUT);
- }
- //-------------------------
- void loop()
- {
- if (irrecv.decode(&results))
- {
- Serial.println(brightness);
- if (results.value == 0xFF6897) //button 1 // Red Button
- {
- setColor(255, 0, 0); // Sets Red Color to the RGB LED
- delay(100);
- }
- if (results.value == 0xFF9867) // Yellow Button //button 2
- {
- setColor(255, 255, 0); // Yellow Color
- delay(100);
- }
- if (results.value == 0xFF02FD) // Stop Button //button OK
- {
- setColor(0, 0, 0); // OFF
- delay(100);
- }
- if (i1 == 0 && results.value == 0xFFB04F) //button 3
- {
- digitalWrite(6, HIGH);
- i1 = 1;
- }
- else if (i1 == 1 && results.value == 0xFFB04F) //button 3
- {
- digitalWrite(6, LOW);
- i1 = 0;
- }
- else if (i2 == 0 && results.value == 0xFF30CF) //button 4
- {
- digitalWrite(5, HIGH);
- i2 = 1;
- }
- else if (i2 == 1 && results.value == 0xFF30CF) //button 4
- {
- digitalWrite(5, LOW);
- i2 = 0;
- }
- else if (i3 == 0 && results.value == 0xFF18E7) //button 5
- {
- digitalWrite(3, HIGH);
- i3 = 1;
- }
- else if (i3 == 1 && results.value == 0xFF18E7) //button 5
- {
- digitalWrite(3, LOW);
- i3 = 0;
- }
- else if (i4 == 0 && results.value == 0xFF7A85) //button 6
- {
- digitalWrite(2, HIGH);
- i4 = 1;
- }
- else if (i4 == 1 && results.value == 0xFF7A85) //button 6
- {
- digitalWrite(2, LOW);
- i4 = 0;
- }
- else if (i5 == 0 && results.value == 0xFF10EF) //button 7
- {
- digitalWrite(10, HIGH);
- i5 = 1;
- pot();
- }
- else if (i5 == 1 && results.value == 0xFF10EF) //button 7
- {
- digitalWrite(10, LOW);
- i5 = 0;
- }
- else if (i6 == 0 && results.value == 0xFD32CD) //button 8
- {
- digitalWrite(11, HIGH);
- i6 = 1;
- fade();
- }
- else if (i6 == 1 && results.value == 0xFF38C7) //button 8
- {
- digitalWrite(11, LOW);
- i6 = 0;
- }
- irrecv.resume();
- }
- delay(100);
- }
- //-------------------------------------//rgb led
- void setColor(int red, int green, int blue)
- {
- analogWrite(redPin, red);
- analogWrite(greenPin, green);
- analogWrite(bluePin, blue);
- }
- //-------------------------
- void pot() {
- valPotenciometro = analogRead(potenciometro) / 4; //potmotor
- analogWrite(transTIP120, valPotenciometro);
- }
- //-------------------------
- void fade()
- {
- Serial.println(brightness);
- analogWrite(led, brightness); //fade led
- brightness = brightness + fadeAmount;
- if (brightness == 0 || brightness == 255)
- {
- fadeAmount = -fadeAmount ;
- }
- delay(30);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement