Skip to content

Instantly share code, notes, and snippets.

@maditnerd
Created April 30, 2013 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maditnerd/5489092 to your computer and use it in GitHub Desktop.
Save maditnerd/5489092 to your computer and use it in GitHub Desktop.
Description: Récepteur / Emetteur de code 433.92Mhz Auteur : Sarrailh Rémi Licence : Gplv3 Mode Apprentissage qui envoie sur le port série le code en décimal Mode envoi qui reçoit sur le port série le code en décimal et l'envoi à l'émetteur Emetteur sur Pin 8 Récepteur sur Pin 2 (Interrupt 0) Switch (ON/OFF) sur pin 5 LED RGB avec anode commune …
/*
Description: Récepteur / Emetteur de code 433.92Mhz
Auteur : Sarrailh Rémi
Licence : Gplv3
Mode Apprentissage qui envoie sur le port
série le code en décimal
Mode envoi qui reçoit sur le port série le code en décimal
et l'envoi à l'émetteur
Emetteur sur Pin 8
Récepteur sur Pin 2 (Interrupt 0)
Switch (ON/OFF) sur pin 5
LED RGB avec anode commune sur Pin 7/6
Nécessite la bibliothèqe RCSwitch
*/
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
long prevvalue = 0;
int correctvalue = 0;
String readString = "";
int mode = 0;
int bouton = 5;
int led_rouge = 7;
int led_verte = 6;
int rx = 0;
int tx = 8;
void setup() {
Serial.begin(9600);
pinMode(bouton,INPUT_PULLUP);
pinMode(led_rouge,OUTPUT);
pinMode(led_verte,OUTPUT);
digitalWrite(led_rouge,HIGH);
digitalWrite(led_verte,HIGH);
if (digitalRead(bouton) == 1)
{
temoinAllumage(led_rouge,200,5);
mySwitch.enableReceive(rx); // Receiver on inerrupt 0 => that is pin #2
mode = 1;
}
if (digitalRead(bouton) == 0)
{
temoinAllumage(led_verte,200,5);
mySwitch.enableTransmit(tx);
mode = 0;
}
}
void loop() {
//Mode Envoi
if (mode == 0)
{
while (Serial.available()) {
lire_serie();
}
if (readString.length() > 0) {
Serial.println(readString); //Voit ce qui a été récupéré
mySwitch.send(readString.toInt(),24);
readString = "";
}
}
if (mode == 1)
{
//Mode apprentissage
if (mySwitch.available()) {
long value = mySwitch.getReceivedValue();
if (value != prevvalue)
{
correctvalue = 0;
prevvalue = value;
}
else
{
correctvalue++;
}
if (correctvalue == 3)
{
Serial.print(value);
}
}
mySwitch.resetAvailable();
}
}
void temoinAllumage(int led_select,int delai,int nb)
{
int i = 0;
while(i < nb)
{
digitalWrite(led_select,HIGH);
delay(delai);
digitalWrite(led_select,LOW);
delay(delai);
i++;
}
}
void lire_serie() {
delay(3);
// Récupère les données
if (Serial.available() > 0) {
char c = Serial.read();
readString += c;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment