Tutoriel 4 : ajout de la matrice de led

This commit is contained in:
Philippe Roy 2023-05-07 03:02:33 +02:00
parent 091805e757
commit b4762f276e
3 changed files with 58 additions and 31 deletions

View File

@ -29,6 +29,7 @@ float roll_deg;
float pitch_deg; float pitch_deg;
String roll_txt; String roll_txt;
String pitch_txt; String pitch_txt;
String serial_msg_int_txt;
/****************************************************************************** /******************************************************************************
* Led Matrix - I2C * Led Matrix - I2C
@ -41,7 +42,8 @@ Matrix_8x8 matrix;
******************************************************************************/ ******************************************************************************/
String serial_msg = ""; // Message String serial_msg = ""; // Message
/* int serial_msg_int; */ uint64_t serial_msg_int;
String serial_msg_old = ""; // Message
bool serial_msg_complet = false; // Flag de message complet bool serial_msg_complet = false; // Flag de message complet
/****************************************************************************** /******************************************************************************
@ -63,16 +65,13 @@ void setup() {
matrix.init(); matrix.init();
matrix.setBrightness(0); matrix.setBrightness(0);
matrix.setBlinkRate(BLINK_OFF); matrix.setBlinkRate(BLINK_OFF);
matrix.clear();
matrix.display();
// Ok // Ok
// Serial.println("Initialisation des composants I2C."); // Serial.println("Initialisation des composants I2C.");
} }
// uint64_t StrToHex(String str)
// {
// return (strtoul(str, 0, 16));
// }
/****************************************************************************** /******************************************************************************
* Boucle principale * Boucle principale
******************************************************************************/ ******************************************************************************/
@ -91,7 +90,7 @@ void loop() {
roll_deg = roll*57.3; roll_deg = roll*57.3;
roll_txt = String(roll_deg); roll_txt = String(roll_deg);
/* pitch = asin(Axyz[1]/cos(roll)); */ /* pitch = asin(Axyz[1]/cos(roll)); */
pitch = -asin(Axyz[1]/cos(roll)); // positio capteur (X vers la gauche, Y vers l'arriere, Z vers le haut) pitch = -asin(Axyz[1]/cos(roll)); // position capteur (X vers la gauche, Y vers l'arriere, Z vers le haut)
pitch_deg = pitch*57.3; pitch_deg = pitch*57.3;
pitch_txt = String(pitch_deg); pitch_txt = String(pitch_deg);
@ -107,25 +106,27 @@ void loop() {
/***** /*****
* Led Matrix : UPBGE -> Arduino * Led Matrix : UPBGE -> Arduino
* https://xantorohara.github.io/led-matrix-editor
* labyrinte : 0xff90b2a2a6a4ae82
*****/ *****/
//matrix.writeNumber(0, 1);
//matrix.display();
if (serial_msg_complet) { if (serial_msg_complet) {
//msg_int = serial_msg.toInt(); /* matrix.writeString(serial_msg, 1000, ACTION_SCROLLING); */
//matrix.writeNumber(msg_int, 1); /* matrix.display(); */
if (serial_msg.length() ==2) {
//matrix.writeOnePicture(0x3c4299a581a5423c); if (serial_msg[0] == 'X') matrix.clear();
//matrix.writeOnePicture(StrToHex(serial_msg)); if (serial_msg[0] == 'N') matrix.writeOnePicture(0x00000000000000ff);
//matrix.writeOnePicture(strtoul(serial_msg, 0, 16)); if (serial_msg[0] == 'E') matrix.writeOnePicture(0x8080808080808080);
//HexInt = serial_msg.toInt(); if (serial_msg[0] == 'S') matrix.writeOnePicture(0xff00000000000000);
//HexInt = serial_msg.parseInt(); if (serial_msg[0] == 'O') matrix.writeOnePicture(0x0101010101010101);
/* matrix.writeOnePicture(serial_msg_int); */ }
//matrix.writeOnePicture(0x8080808080808080); if (serial_msg.length() ==3) {
if ((serial_msg[0] == 'N') and (serial_msg[1] == 'E')) matrix.writeOnePicture(0x00000000808080f0);
if ((serial_msg[0] == 'S') and (serial_msg[1] == 'E')) matrix.writeOnePicture(0xf080808000000000);
if ((serial_msg[0] == 'S') and (serial_msg[1] == 'O')) matrix.writeOnePicture(0x0f01010100000000);
if ((serial_msg[0] == 'N') and (serial_msg[1] == 'O')) matrix.writeOnePicture(0x000000000101010f);
}
matrix.display(); matrix.display();
//if (serial_msg =="Bp Am R\n") bt_a_m_num=false;
serial_msg = ""; serial_msg = "";
serial_msg_complet = false; serial_msg_complet = false;
} }

View File

@ -90,23 +90,49 @@ def capteur(cont):
bge.logic.endGame() bge.logic.endGame()
# Lecture de la liaison série : programme Arduino : 3-labyrinthe-imu.ino # Lecture de la liaison série : programme Arduino : 3-labyrinthe-imu.ino
obj['Rx']=obj.worldOrientation.to_euler().x
obj['Ry']=obj.worldOrientation.to_euler().y
obj['Rz']=obj.worldOrientation.to_euler().z
serial_msg_in = str(serial_comm.readline()) serial_msg_in = str(serial_comm.readline())
# Affiche le message uniquement
if serial_msg_in.find("Print")>0 or serial_msg_in.find("Debug")>0 or serial_msg_in.find("Echo")>0:
print ("Communication port série : ", serial_msg_in)
serial_msg_in=""
return
# Roll et Pitch
if serial_msg_in.find(",")>0: if serial_msg_in.find(",")>0:
txt = serial_msg_in.split(',',2) txt = serial_msg_in.split(',',2)
x_txt = txt[0][2:] x_txt = txt[0][2:]
y_txt = txt[1][:-5] y_txt = txt[1][:-5]
x=-(float(x_txt)/57.3) * resolution # 1/ 360 / (2 * pi) x=-(float(x_txt)/57.3) * resolution # 1/ 360 / (2 * pi)
y=-(float(y_txt)/57.3) * resolution # 1/ 360 / (2 * pi) y=-(float(y_txt)/57.3) * resolution # 1/ 360 / (2 * pi)
# Roll et Pitch
applyRotationTo(scene.objects['Plateau'], x,y, 0) applyRotationTo(scene.objects['Plateau'], x,y, 0)
# Ecriture sur la liaison série : programme Arduino : 3-labyrinthe-imu.ino # Ecriture sur la liaison série : programme Arduino : 3-labyrinthe-imu.ino
serial_msg_out = "9259542123273814144\n " # "8080808080808080\n" obj['Rx']=obj.worldOrientation.to_euler().x*57.3
# serial_msg_out = "2\n" obj['Ry']=obj.worldOrientation.to_euler().y*57.3
obj['Rz']=obj.worldOrientation.to_euler().z*57.3
if obj['Rx']<-2 and obj['Ry'] >-2 and obj['Ry'] <2:
serial_msg_out = "N\n"
if obj['Rx']>2 and obj['Ry'] >-2 and obj['Ry'] <2:
serial_msg_out = "S\n"
if obj['Rx']>-2 and obj['Rx']<2 and obj['Ry'] <-2 :
serial_msg_out = "O\n"
if obj['Rx']>-2 and obj['Rx']<2 and obj['Ry'] > 2 :
serial_msg_out = "E\n"
if obj['Rx']<-2 and obj['Ry'] <-2 :
serial_msg_out = "NO\n"
if obj['Rx']<-2 and obj['Ry'] > 2 :
serial_msg_out = "NE\n"
if obj['Rx']>2 and obj['Ry'] <-2 :
serial_msg_out = "SO\n"
if obj['Rx']>2 and obj['Ry'] > 2 :
serial_msg_out = "SE\n"
if obj['Rx']>-2 and obj['Rx']<2 and obj['Ry'] >-2 and obj['Ry'] <2:
serial_msg_out = "X\n"
serial_comm.write(serial_msg_out.encode()) serial_comm.write(serial_msg_out.encode())
############################################################################### ###############################################################################