2020-05-12 09:52:03 +02:00
|
|
|
#include <unistd.h>
|
|
|
|
#include "core_simulation.h"
|
|
|
|
|
|
|
|
// la fonction d'initialisation d'arduino
|
|
|
|
void Board::setup(){
|
|
|
|
// on configure la vitesse de la liaison
|
|
|
|
Serial.begin(9600);
|
|
|
|
// on fixe les pin en entree et en sorite en fonction des capteurs/actionneurs mis sur la carte
|
|
|
|
pinMode(1,INPUT);
|
|
|
|
pinMode(0,OUTPUT);
|
2020-05-12 11:43:08 +02:00
|
|
|
pinMode(2,INPUT);
|
2020-05-12 09:52:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// la boucle de controle arduino
|
|
|
|
void Board::loop(){
|
|
|
|
char buf[100];
|
|
|
|
int val;
|
2020-05-12 11:22:59 +02:00
|
|
|
int val1;
|
2020-05-12 09:52:03 +02:00
|
|
|
static int cpt=0;
|
|
|
|
static int bascule=0;
|
|
|
|
int i=0;
|
|
|
|
for(i=0;i<10;i++){
|
2020-05-12 11:43:08 +02:00
|
|
|
// lecture sur la pin 1 : capteur de temperature
|
|
|
|
val1=analogRead(1);
|
|
|
|
sprintf(buf,"temperature %d",val1);
|
|
|
|
Serial.println(buf);
|
2020-05-12 11:22:59 +02:00
|
|
|
|
|
|
|
// lecture sur la pin 2 : capteur de temperature
|
|
|
|
val=analogRead(2);
|
|
|
|
sprintf(buf,"luminosite %d",val);
|
|
|
|
Serial.println(buf);
|
|
|
|
|
2020-05-12 09:52:03 +02:00
|
|
|
if(cpt%5==0){
|
|
|
|
// tous les 5 fois on affiche sur l ecran la temperature
|
2020-05-12 11:22:59 +02:00
|
|
|
sprintf(buf,"%d",val1);
|
2020-05-12 09:52:03 +02:00
|
|
|
bus.write(1,buf,100);
|
2020-05-12 11:22:59 +02:00
|
|
|
|
|
|
|
|
2020-05-12 09:52:03 +02:00
|
|
|
}
|
|
|
|
cpt++;
|
|
|
|
sleep(1);
|
|
|
|
}
|
|
|
|
// on eteint et on allume la LED
|
|
|
|
if(bascule)
|
|
|
|
digitalWrite(0,HIGH);
|
|
|
|
else
|
|
|
|
digitalWrite(0,LOW);
|
|
|
|
bascule=1-bascule;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|