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;
String roll_txt;
String pitch_txt;
String serial_msg_int_txt;
/******************************************************************************
* Led Matrix - I2C
@ -40,8 +41,9 @@ Matrix_8x8 matrix;
* Communication serie
******************************************************************************/
String serial_msg = ""; // Message
/* int serial_msg_int; */
String serial_msg = ""; // Message
uint64_t serial_msg_int;
String serial_msg_old = ""; // Message
bool serial_msg_complet = false; // Flag de message complet
/******************************************************************************
@ -63,16 +65,13 @@ void setup() {
matrix.init();
matrix.setBrightness(0);
matrix.setBlinkRate(BLINK_OFF);
matrix.clear();
matrix.display();
// Ok
// Serial.println("Initialisation des composants I2C.");
}
// uint64_t StrToHex(String str)
// {
// return (strtoul(str, 0, 16));
// }
/******************************************************************************
* Boucle principale
******************************************************************************/
@ -91,7 +90,7 @@ void loop() {
roll_deg = roll*57.3;
roll_txt = String(roll_deg);
/* 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_txt = String(pitch_deg);
@ -104,28 +103,30 @@ void loop() {
Serial.print(",");
Serial.print(pitch_txt);
Serial.println();
/*****
* Led Matrix : UPBGE -> Arduino
* https://xantorohara.github.io/led-matrix-editor
* labyrinte : 0xff90b2a2a6a4ae82
*****/
//matrix.writeNumber(0, 1);
//matrix.display();
if (serial_msg_complet) {
//msg_int = serial_msg.toInt();
//matrix.writeNumber(msg_int, 1);
//matrix.writeOnePicture(0x3c4299a581a5423c);
//matrix.writeOnePicture(StrToHex(serial_msg));
//matrix.writeOnePicture(strtoul(serial_msg, 0, 16));
//HexInt = serial_msg.toInt();
//HexInt = serial_msg.parseInt();
/* matrix.writeOnePicture(serial_msg_int); */
//matrix.writeOnePicture(0x8080808080808080);
/* matrix.writeString(serial_msg, 1000, ACTION_SCROLLING); */
/* matrix.display(); */
if (serial_msg.length() ==2) {
if (serial_msg[0] == 'X') matrix.clear();
if (serial_msg[0] == 'N') matrix.writeOnePicture(0x00000000000000ff);
if (serial_msg[0] == 'E') matrix.writeOnePicture(0x8080808080808080);
if (serial_msg[0] == 'S') matrix.writeOnePicture(0xff00000000000000);
if (serial_msg[0] == 'O') matrix.writeOnePicture(0x0101010101010101);
}
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();
//if (serial_msg =="Bp Am R\n") bt_a_m_num=false;
serial_msg = "";
serial_msg_complet = false;
}

View File

@ -90,23 +90,49 @@ def capteur(cont):
bge.logic.endGame()
# 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())
# 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:
txt = serial_msg_in.split(',',2)
x_txt = txt[0][2:]
y_txt = txt[1][:-5]
x=-(float(x_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)
# Ecriture sur la liaison série : programme Arduino : 3-labyrinthe-imu.ino
serial_msg_out = "9259542123273814144\n " # "8080808080808080\n"
# serial_msg_out = "2\n"
obj['Rx']=obj.worldOrientation.to_euler().x*57.3
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())
###############################################################################