Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //by steef
- const float seuil = 3.4;// voltage seuil en sorti de la photodiode
- const int thisPin = 0;//pin sur laquel est branché la led
- const int duree_bit = 100 ;//duré d'un bit (NRZ) en millisecondes
- const int TAILLETRAME = 9*8; //nb bit dans la trame
- unsigned char TRAME[TAILLETRAME];
- bool ValBit(int thisPin);
- unsigned char bintochar(unsigned char* TRAME, int debut);
- void setup() {
- pinMode(13, OUTPUT);
- Serial.begin(9600);
- }
- void loop() {
- if (ValBit(thisPin)== false){
- Serial.println("DEBUT");
- delay(duree_bit);
- for(int i =0; i< TAILLETRAME; i++)
- {
- if (ValBit(thisPin)== false)
- {
- TRAME[i]=0;
- //Serial.println("0");
- analogWrite(13, 0);
- }
- else
- {
- TRAME[i]=1;
- //Serial.println("1");
- analogWrite(13, 255);
- }
- delay(duree_bit);
- }
- int j =0;
- for(int i=0;i<TAILLETRAME/8;i++)
- {
- Serial.println(char(bintochar(TRAME,j)));
- j=j+8;
- }
- }
- }
- bool ValBit(int thisPin){
- int diode = analogRead(thisPin);
- float voltage = diode * (5.0 / 1023.0);
- if(voltage <= seuil)
- return false;
- else
- return true;
- }
- unsigned char bintochar(unsigned char* TRAME, int debut){
- unsigned char val=0;
- int poid =128;
- for(int i=debut;i<debut+8;i++)
- {
- //Serial.println(int(TRAME[i]));
- val=val+(int(TRAME[i])*poid);
- poid = poid/2;
- }
- return val;
- }
Add Comment
Please, Sign In to add comment