mirror of
https://forge.apps.education.fr/blender-edutech/ropy.git
synced 2024-01-27 08:23:20 +01:00
104 lines
2.9 KiB
Arduino
104 lines
2.9 KiB
Arduino
|
/******************************************************************************
|
||
|
* arduino-serialreader.ino
|
||
|
* @title: Lecteur du port serie d'une carte arduino
|
||
|
* @project: Ropy (Blender-EduTech)
|
||
|
* @lang: fr
|
||
|
* @authors: Philippe Roy <philippe.roy@ac-grenoble.fr>
|
||
|
* @copyright: Copyright (C) 2022 Philippe Roy
|
||
|
* @license: GNU GPL
|
||
|
******************************************************************************/
|
||
|
|
||
|
/******************************************************************************
|
||
|
* Pupitre
|
||
|
******************************************************************************/
|
||
|
|
||
|
// Adressage Led Arduino
|
||
|
/* const int led = 13; // Led de mouvement (onboard) */
|
||
|
/* const int led_com = 10; // Led de communication modele 3d-> arduino */
|
||
|
const int bt = 2; // Bouton
|
||
|
const int v = 3; // Voyant
|
||
|
|
||
|
/******************************************************************************
|
||
|
* Communication serie
|
||
|
******************************************************************************/
|
||
|
|
||
|
String serial_msg = ""; // Message
|
||
|
bool serial_msg_complet = false; // Flag de message complet
|
||
|
|
||
|
/******************************************************************************
|
||
|
* Initialisation
|
||
|
******************************************************************************/
|
||
|
|
||
|
void setup() {
|
||
|
|
||
|
pinMode(bt, INPUT); // Bouton
|
||
|
pinMode(v, OUTPUT); // Voyant
|
||
|
/* pinMode(led, OUTPUT); // Led de mouvement */
|
||
|
/* pinMode(led_com, OUTPUT); // Led de communication modele 3d-> arduino */
|
||
|
digitalWrite(v, LOW);
|
||
|
/* digitalWrite(led, LOW); */
|
||
|
/* digitalWrite(led_com, LOW); */
|
||
|
|
||
|
Serial.begin(115200); // Moniteur serie
|
||
|
}
|
||
|
|
||
|
/******************************************************************************
|
||
|
* Boucle principale
|
||
|
******************************************************************************/
|
||
|
|
||
|
void loop() {
|
||
|
|
||
|
/*****
|
||
|
* Communication : modele 3d -> arduino
|
||
|
*****/
|
||
|
|
||
|
if (serial_msg_complet) {
|
||
|
|
||
|
if (serial_msg =="S\n") bt_num=true; // S pour Set
|
||
|
if (serial_msg =="R\n") bt_num=false; // R pour Reset
|
||
|
|
||
|
Serial.println("Echo : "+serial_msg);
|
||
|
serial_msg = "";
|
||
|
serial_msg_complet = false;
|
||
|
}
|
||
|
|
||
|
/*****
|
||
|
* Bouton (arduino -> modele 3d)
|
||
|
*
|
||
|
* Bouton physique : LOW = actif et HIGH = pas actif
|
||
|
*****/
|
||
|
|
||
|
if digitalRead(bt) == LOW {
|
||
|
Serial.println("B");
|
||
|
}
|
||
|
|
||
|
/*****
|
||
|
* Yoyant modele 3d-> arduino
|
||
|
*
|
||
|
* Bouton numérique (modele 3d) : true = actif et false = pas actif
|
||
|
*****/
|
||
|
|
||
|
if bt_num == true {
|
||
|
digitalWrite(v, HIGH);
|
||
|
}
|
||
|
if bt_num == false {
|
||
|
digitalWrite(v, LOW);
|
||
|
}
|
||
|
|
||
|
/* delay(300); */
|
||
|
}
|
||
|
|
||
|
/******************************************************************************
|
||
|
* Evenements provoques par la communication serie
|
||
|
******************************************************************************/
|
||
|
|
||
|
void serialEvent() {
|
||
|
while (Serial.available()) {
|
||
|
char inChar = (char)Serial.read();
|
||
|
serial_msg += inChar;
|
||
|
if (inChar == '\n') {
|
||
|
serial_msg_complet = true;
|
||
|
}
|
||
|
}
|
||
|
}
|