0% found this document useful (0 votes)
12 views2 pages

Code Gloire

Uploaded by

gloireelie61
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

Code Gloire

Uploaded by

gloireelie61
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

// C++ code

//
#include <IRremote.h>

int bouton = 0;

bool etat_relais1 = 0;

bool etat_relais2 = 0;

bool etat_relais3 = 0;

bool etat_relais4 = 0;

int unnamed = 0;

// Map the IR code to the corresponding remote button.


// The buttons are in this order on the remote:
// 0 1 2
// 4 5 6
// 8 9 10
// 12 13 14
// 16 17 18
// 20 21 22
// 24 25 26
//
// Return -1, if supplied code does not map to a key.
int mapCodeToButton(unsigned long code) {
// For the remote used in the Tinkercad simulator,
// the buttons are encoded such that the hex code
// received is of the format: 0xiivvBF00
// Where the vv is the button value, and ii is
// the bit-inverse of vv.
// For example, the power button is 0xFF00BF000

// Check for codes from this specific remote


if ((code & 0x0000FFFF) == 0x0000BF00) {
// No longer need the lower 16 bits. Shift the code by 16
// to make the rest easier.
code >>= 16;
// Check that the value and inverse bytes are complementary.
if (((code >> 8) ^ (code & 0x00FF)) == 0x00FF) {
return code & 0xFF;
}
}
return -1;
}

int readInfrared() {
int result = -1;
// Check if we've received a new code
if (IrReceiver.decode()) {
// Get the infrared code
unsigned long code = IrReceiver.decodedIRData.decodedRawData;
// Map it to a specific button on the remote
result = mapCodeToButton(code);
// Enable receiving of the next value
IrReceiver.resume();
}
return result;
}
void setup()
{
pinMode(11, OUTPUT);
IrReceiver.begin(2);

pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);

digitalWrite(11, HIGH);
}

void loop()
{
bouton = readInfrared();
if (bouton == 16) {
etat_relais1 = !etat_relais1;
digitalWrite(3, etat_relais1);
} else {
if (bouton == 17) {
etat_relais2 = !etat_relais2;
digitalWrite(4, etat_relais2);
} else {
if (bouton == 18) {
etat_relais3 = !etat_relais3;
digitalWrite(5, etat_relais3);
} else {
if (bouton == 20) {
etat_relais4 = !etat_relais4;
digitalWrite(6, etat_relais4);
} else {
if (bouton == 21) {
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
} else {
if (bouton == 0) {
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
} else {
}
}
}
}
}
}
delay(10); // Delay a little bit to improve simulation performance
}

You might also like