mirror of
https://forge.apps.education.fr/blender-edutech/blender-edutech-tutoriels.git
synced 2024-01-27 09:42:33 +01:00
Tutoriel 4 : étape 1
This commit is contained in:
parent
62bd592acd
commit
f5455cad9b
Binary file not shown.
Binary file not shown.
@ -1,168 +0,0 @@
|
||||
#include "Wire.h"
|
||||
#include "Grove_LED_Matrix_Driver_HT16K33.h"
|
||||
#include "MPU6050.h"
|
||||
|
||||
/******************************************************************************
|
||||
* 4-labyrinthe-imu.ino
|
||||
* @title: Programme pour la carte Arduino de gestion de centrale inertielle (capteur IMU)
|
||||
* @project: Blender-EduTech - Tutoriel 3 : Labyrinthe à bille - Interfacer avec une carte Arduino par la liaision série
|
||||
* @lang: fr
|
||||
* @authors: Philippe Roy <philippe.roy@ac-grenoble.fr>
|
||||
* @copyright: Copyright (C) 2023 Philippe Roy
|
||||
* @license: GNU GPL
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* IMU - I2C
|
||||
******************************************************************************/
|
||||
|
||||
MPU6050 accelgyro;
|
||||
|
||||
int16_t ax, ay, az;
|
||||
int16_t gx, gy, gz;
|
||||
int16_t mx, my, mz;
|
||||
float Axyz[3];
|
||||
float roll;
|
||||
float pitch;
|
||||
float roll_deg;
|
||||
float pitch_deg;
|
||||
String roll_txt;
|
||||
String pitch_txt;
|
||||
String serial_msg_int_txt;
|
||||
|
||||
/******************************************************************************
|
||||
* Led Matrix - I2C
|
||||
******************************************************************************/
|
||||
|
||||
Matrix_8x8 matrix;
|
||||
|
||||
/******************************************************************************
|
||||
* Communication serie
|
||||
******************************************************************************/
|
||||
|
||||
String serial_msg = ""; // Message
|
||||
bool serial_msg_complet = false; // Flag de message complet
|
||||
|
||||
/******************************************************************************
|
||||
* Initialisation
|
||||
******************************************************************************/
|
||||
|
||||
void setup() {
|
||||
|
||||
// Liaison série
|
||||
Serial.begin(115200);
|
||||
|
||||
// IMU
|
||||
Wire.begin();
|
||||
accelgyro.initialize();
|
||||
|
||||
// Led Matrix
|
||||
matrix.init();
|
||||
matrix.setBrightness(0);
|
||||
matrix.setBlinkRate(BLINK_OFF);
|
||||
matrix.clear();
|
||||
matrix.display();
|
||||
/* matrix.writeOnePicture(0xff90b2a2a6a4ae82); // Labyrinthe */
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Boucle principale
|
||||
******************************************************************************/
|
||||
|
||||
void loop() {
|
||||
|
||||
/*****
|
||||
* Lecture des accélérations
|
||||
*****/
|
||||
|
||||
accelgyro.getMotion9(&ax, &ay, &az, &gx, &gy, &gz, &mx, &my, &mz);
|
||||
Axyz[0] = (double) ax / 16384;
|
||||
Axyz[1] = (double) ay / 16384;
|
||||
Axyz[2] = (double) az / 16384;
|
||||
roll = asin(-Axyz[0]);
|
||||
roll_deg = roll*57.3;
|
||||
roll_txt = String(roll_deg);
|
||||
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);
|
||||
|
||||
/*****
|
||||
* IMU : Arduino -> UPBGE
|
||||
*****/
|
||||
|
||||
Serial.print(roll_txt);
|
||||
Serial.print(",");
|
||||
Serial.print(pitch_txt);
|
||||
Serial.println();
|
||||
|
||||
/*****
|
||||
* Led Matrix : UPBGE -> Arduino
|
||||
*****/
|
||||
if (serial_msg_complet) {
|
||||
matrix.clear();
|
||||
int xy= serial_msg.toInt(); // Message par chiffre : XY
|
||||
|
||||
// Postion de la bille en x et y
|
||||
int x= xy/10;
|
||||
int y= xy-(x*10);
|
||||
if (xy<90) matrix.writePixel(x, y, true);
|
||||
|
||||
// Départ - Flèches
|
||||
if (xy==90) {
|
||||
matrix.writeOnePicture(0xe7c3a51818a5c3e7);
|
||||
matrix.display();
|
||||
delay(500);
|
||||
Serial.println("start"); // Relance le jeu
|
||||
}
|
||||
|
||||
// Chute
|
||||
if (xy==91) {
|
||||
matrix.writeOnePicture(0x81423c0000666600);
|
||||
matrix.display();
|
||||
delay(500);
|
||||
Serial.println("start"); // Relance le jeu
|
||||
}
|
||||
|
||||
// Victoire
|
||||
if (xy==92) {
|
||||
/* matrix.writeIcon(10); */
|
||||
matrix.writeOnePicture(0x003c428100666600);
|
||||
}
|
||||
|
||||
/* Orientation du plateau (N, NE, SE, S, SO, O, NO) */
|
||||
/* 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();
|
||||
serial_msg = "";
|
||||
serial_msg_complet = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* Évenement provoqué UPBGE (via la liaison série)
|
||||
******************************************************************************/
|
||||
|
||||
void serialEvent() {
|
||||
while (Serial.available()) {
|
||||
char inChar = (char)Serial.read();
|
||||
serial_msg += inChar;
|
||||
if (inChar == '\n') {
|
||||
serial_msg_complet = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,336 +0,0 @@
|
||||
/*
|
||||
Grove_LED_Matrix_Driver_HT16K33.cpp
|
||||
A library for Grove - Grove - LED Matrix Driver(HT16K33 with 8x8 LED Matrix)
|
||||
|
||||
Copyright (c) 2018 seeed technology inc.
|
||||
Website : www.seeed.cc
|
||||
Author : Jerry Yip
|
||||
Create Time: 2018-06
|
||||
Version : 0.1
|
||||
Change Log :
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "Grove_LED_Matrix_Driver_HT16K33.h"
|
||||
#include "Seeed_Font.h"
|
||||
|
||||
|
||||
HT16K33::HT16K33() {
|
||||
}
|
||||
|
||||
void HT16K33::init(uint8_t addr) {
|
||||
_addr = addr;
|
||||
// turn on oscillator
|
||||
I2Cdev::writeBytes(_addr, 0x21, 0, (uint8_t*)NULL);
|
||||
}
|
||||
|
||||
void HT16K33::setBrightness(uint8_t brightness) {
|
||||
I2Cdev::writeBytes(_addr, (0xE0 | brightness), 0, (uint8_t*)NULL);
|
||||
}
|
||||
|
||||
|
||||
void HT16K33::setBlinkRate(blink_type_t blink_type) {
|
||||
I2Cdev::writeBytes(_addr, (0x80 | 0x01 | (blink_type << 1)), 0, (uint8_t*)NULL);
|
||||
}
|
||||
|
||||
Matrix_8x8::Matrix_8x8() {
|
||||
_orientation = DISPLAY_ROTATE_0;
|
||||
_offset_x = 0;
|
||||
_offset_y = 0;
|
||||
_cursor_start = 0;
|
||||
_cursor_end = 0;
|
||||
_cursor_steps = 1;
|
||||
_ms = 100;
|
||||
}
|
||||
|
||||
void Matrix_8x8::setDisplayOffset(int8_t x, int8_t y) {
|
||||
if ((x < -8) || (x > 8)) {
|
||||
return;
|
||||
}
|
||||
if ((y < -8) || (y > 8)) {
|
||||
return;
|
||||
}
|
||||
_offset_x = x;
|
||||
_offset_y = y;
|
||||
}
|
||||
|
||||
void Matrix_8x8::setDisplayOrientation(uint8_t orientation) {
|
||||
_orientation = (orientation_type_t)orientation;
|
||||
}
|
||||
|
||||
// _cursor_end - _cursor_start >= 1
|
||||
void Matrix_8x8::display() {
|
||||
// get data from _big_buffer[] and write to HT16K33
|
||||
uint8_t line;
|
||||
|
||||
if (_cursor_start > _cursor_end) {
|
||||
uint16_t t;
|
||||
t = _cursor_start;
|
||||
_cursor_start = _cursor_end;
|
||||
_cursor_end = t;
|
||||
}
|
||||
|
||||
for (int32_t i = _cursor_start; i <= _cursor_end; i = i + _cursor_steps) {
|
||||
for (uint8_t j = 0; j < 8; j++) {
|
||||
// test
|
||||
line = _big_buffer[(MAX_BIG_BUFFER_SIZE - 8 - i) + j];
|
||||
for (uint8_t k = 0; k < 8; k++) {
|
||||
if (line & 0x01) {
|
||||
// set 1
|
||||
_buffer[2 * j] |= (1 << k);
|
||||
} else {
|
||||
// set 0
|
||||
_buffer[2 * j] &= ~(1 << k);
|
||||
}
|
||||
line = line >> 1;
|
||||
}
|
||||
}
|
||||
// offset
|
||||
if (_offset_y > 0) {
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
_buffer[2 * i] = (_buffer[2 * i] >> _offset_y);
|
||||
}
|
||||
} else if (_offset_y < 0) {
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
_buffer[2 * i] = (_buffer[2 * i] << (-_offset_y));
|
||||
}
|
||||
}
|
||||
if (_offset_x > 0) {
|
||||
for (int8_t i = (7 - _offset_x); i >= 0; i--) {
|
||||
_buffer[2 * (i + _offset_x)] = _buffer[2 * i];
|
||||
}
|
||||
for (uint8_t i = 0; i < _offset_x; i++) {
|
||||
_buffer[2 * i] = 0;
|
||||
}
|
||||
} else if (_offset_x < 0) {
|
||||
for (uint8_t i = (-_offset_x); i < 8; i++) {
|
||||
_buffer[2 * (i + _offset_x)] = _buffer[2 * i];
|
||||
}
|
||||
|
||||
for (uint8_t i = (8 + _offset_x); i < 8; i++) {
|
||||
_buffer[2 * i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
I2Cdev::writeBytes(_addr, 0x00, 16, _buffer);
|
||||
delay(_ms);
|
||||
}
|
||||
}
|
||||
|
||||
void Matrix_8x8::clear() {
|
||||
memset(_big_buffer, 0, MAX_BIG_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
void Matrix_8x8::writePixel(uint8_t x, uint16_t y, bool set_on) {
|
||||
if (x > 7) {
|
||||
x = 7;
|
||||
}
|
||||
if (y > (MAX_BIG_BUFFER_SIZE - 1)) {
|
||||
y = MAX_BIG_BUFFER_SIZE - 1;
|
||||
}
|
||||
|
||||
uint8_t y_mod8 = y % 8;
|
||||
// first do spin
|
||||
switch (_orientation) {
|
||||
case DISPLAY_ROTATE_0: {
|
||||
uint8_t t;
|
||||
t = x;
|
||||
x = y_mod8;
|
||||
y_mod8 = t;
|
||||
x = 7 - x;
|
||||
}
|
||||
break;
|
||||
|
||||
// case DISPLAY_ROTATE_90:
|
||||
// break;
|
||||
|
||||
case DISPLAY_ROTATE_180: {
|
||||
uint8_t t;
|
||||
t = x;
|
||||
x = y_mod8;
|
||||
y_mod8 = t;
|
||||
y_mod8 = 7 - y_mod8;
|
||||
}
|
||||
break;
|
||||
|
||||
case DISPLAY_ROTATE_270:
|
||||
y_mod8 = 7 - y_mod8;
|
||||
x = 7 - x;
|
||||
break;
|
||||
}
|
||||
|
||||
if (set_on) {
|
||||
_big_buffer[((MAX_BIG_BUFFER_SIZE / 8 - 1) - (y / 8)) * 8 + y_mod8] |= (1 << x);
|
||||
} else {
|
||||
_big_buffer[((MAX_BIG_BUFFER_SIZE / 8 - 1) - (y / 8)) * 8 + y_mod8] &= ~(1 << x);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Matrix_8x8::writeBar(uint8_t bar) {
|
||||
if (bar > 32) {
|
||||
bar = 32;
|
||||
}
|
||||
Matrix_8x8::writeOnePicture(BARS[bar]);
|
||||
}
|
||||
void Matrix_8x8::writeIcon(uint8_t num) {
|
||||
if (num > 28) {
|
||||
num = 28;
|
||||
}
|
||||
Matrix_8x8::writeOnePicture(ICONS[num]);
|
||||
}
|
||||
|
||||
void Matrix_8x8::writeNumber(int32_t number, uint16_t ms_per_digit) {
|
||||
Matrix_8x8::writeString(String(number), ms_per_digit, ACTION_SCROLLING);
|
||||
}
|
||||
void Matrix_8x8::writeString(String s, uint16_t ms_per_letter, action_type_t mode) {
|
||||
uint8_t pic_number = s.length();
|
||||
if (pic_number > (MAX_BIG_BUFFER_SIZE / 8)) {
|
||||
pic_number = MAX_BIG_BUFFER_SIZE / 8;
|
||||
}
|
||||
if (pic_number == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const char* p_string = s.c_str();
|
||||
_cursor_start = 0;
|
||||
if (mode == ACTION_SCROLLING) {
|
||||
_cursor_steps = 1;
|
||||
|
||||
if (pic_number == 1) {
|
||||
_cursor_end = 0;
|
||||
_ms = ms_per_letter;
|
||||
} else {
|
||||
_cursor_end = pic_number * 8;
|
||||
_ms = ms_per_letter / 8;
|
||||
}
|
||||
} else {
|
||||
if (pic_number == 1) {
|
||||
_cursor_end = 0;
|
||||
} else {
|
||||
_cursor_end = pic_number * 8 - 1;
|
||||
}
|
||||
_cursor_steps = 8;
|
||||
_ms = ms_per_letter;
|
||||
}
|
||||
|
||||
uint64_t frame;
|
||||
uint8_t line;
|
||||
|
||||
memset(_big_buffer, 0, MAX_BIG_BUFFER_SIZE);
|
||||
|
||||
for (uint8_t m = 0; m < pic_number; m++) {
|
||||
frame = ASCII[p_string[m] - 32];
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
line = (uint8_t)(frame & 0xff);
|
||||
for (uint8_t j = 7; j != 255; j--) {
|
||||
if (line & 0x01) {
|
||||
Matrix_8x8::writePixel(j, i + m * 8);
|
||||
}
|
||||
line = line >> 1;
|
||||
}
|
||||
frame = frame >> 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Matrix_8x8::writeOnePicture(const uint8_t *pic) {
|
||||
Matrix_8x8::writePictures(pic, 1, 0, ACTION_SHIFT);
|
||||
}
|
||||
|
||||
// uint64_t pic
|
||||
void Matrix_8x8::writeOnePicture(uint64_t pic) {
|
||||
Matrix_8x8::writePictures((uint64_t*)&pic, 1, 0, ACTION_SHIFT);
|
||||
}
|
||||
|
||||
void Matrix_8x8::writePictures(const uint8_t *pic, uint8_t pic_number, uint16_t ms_per_pic, action_type_t mode) {
|
||||
if (pic_number > (MAX_BIG_BUFFER_SIZE / 8)) {
|
||||
pic_number = MAX_BIG_BUFFER_SIZE / 8;
|
||||
}
|
||||
if (pic_number == 0) {
|
||||
return;
|
||||
}
|
||||
_cursor_start = 0;
|
||||
if (mode == ACTION_SCROLLING) {
|
||||
_cursor_steps = 1;
|
||||
_ms = ms_per_pic / 8;
|
||||
_cursor_end = pic_number * 8;
|
||||
} else {
|
||||
_cursor_end = pic_number * 8 - 1;
|
||||
_cursor_steps = 8;
|
||||
_ms = ms_per_pic;
|
||||
}
|
||||
|
||||
uint8_t line;
|
||||
|
||||
memset(_big_buffer, 0, MAX_BIG_BUFFER_SIZE);
|
||||
|
||||
for (uint8_t i = 0; i < (8 * pic_number); i++) {
|
||||
line = pic[i];
|
||||
for (uint8_t j = 0; j < 8; j++) {
|
||||
if (line & 0x01) {
|
||||
Matrix_8x8::writePixel(j, i);
|
||||
}
|
||||
line = line >> 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Matrix_8x8::writePictures(const uint64_t *pic, uint8_t pic_number, uint16_t ms_per_pic, action_type_t mode) {
|
||||
if (pic_number > (MAX_BIG_BUFFER_SIZE / 8)) {
|
||||
pic_number = MAX_BIG_BUFFER_SIZE / 8;
|
||||
}
|
||||
if (pic_number == 0) {
|
||||
return;
|
||||
}
|
||||
_cursor_start = 0;
|
||||
if (mode == ACTION_SCROLLING) {
|
||||
_cursor_steps = 1;
|
||||
_ms = ms_per_pic / 8;
|
||||
_cursor_end = pic_number * 8;
|
||||
} else {
|
||||
_cursor_end = pic_number * 8 - 1;
|
||||
_cursor_steps = 8;
|
||||
_ms = ms_per_pic;
|
||||
}
|
||||
|
||||
uint64_t frame;
|
||||
uint8_t line;
|
||||
|
||||
memset(_big_buffer, 0, MAX_BIG_BUFFER_SIZE);
|
||||
|
||||
for (uint8_t m = 0; m < pic_number; m++) {
|
||||
frame = pic[m];
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
line = (uint8_t)(frame & 0xff);
|
||||
for (uint8_t j = 7; j != 255; j--) {
|
||||
if (line & 0x01) {
|
||||
Matrix_8x8::writePixel(j, i + m * 8);
|
||||
}
|
||||
line = line >> 1;
|
||||
}
|
||||
frame = frame >> 8;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,278 +0,0 @@
|
||||
/*
|
||||
Grove_LED_Matrix_Driver_HT16K33.h
|
||||
A library for Grove - LED Matrix Driver(HT16K33 with 8x8 LED Matrix)
|
||||
|
||||
Copyright (c) 2018 seeed technology inc.
|
||||
Website : www.seeed.cc
|
||||
Author : Jerry Yip
|
||||
Create Time: 2018-06
|
||||
Version : 0.1
|
||||
Change Log :
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef __GROVE_LED_MATRIX_DRIVER_HT16K33__
|
||||
#define __GROVE_LED_MATRIX_DRIVER_HT16K33__
|
||||
|
||||
#include "I2Cdev.h"
|
||||
|
||||
|
||||
|
||||
#define HT16K33_DEFAULT_I2C_ADDR 0x70
|
||||
// 8*48 means this buffer can store 48 pictures, if you
|
||||
// need more space, please make sure MAX_BIG_BUFFER_SIZE
|
||||
// is a multiple of 8.
|
||||
#define MAX_BIG_BUFFER_SIZE (8*20)
|
||||
|
||||
|
||||
enum orientation_type_t {
|
||||
DISPLAY_ROTATE_0 = 0,
|
||||
DISPLAY_ROTATE_90,
|
||||
DISPLAY_ROTATE_180,
|
||||
DISPLAY_ROTATE_270,
|
||||
};
|
||||
|
||||
enum action_type_t {
|
||||
ACTION_SCROLLING = 0,
|
||||
ACTION_SHIFT,
|
||||
};
|
||||
|
||||
enum blink_type_t {
|
||||
BLINK_OFF = 0,
|
||||
BLINK_2HZ,
|
||||
BLINK_1HZ,
|
||||
};
|
||||
|
||||
class HT16K33 {
|
||||
public:
|
||||
HT16K33();
|
||||
void init(uint8_t addr = HT16K33_DEFAULT_I2C_ADDR);
|
||||
|
||||
/*************************************************************
|
||||
Description
|
||||
Setting the blink rate of matrix
|
||||
Parameter
|
||||
blink_type: BLINK_OFF, BLINK_2HZ, BLINK_1HZ
|
||||
Return
|
||||
Null.
|
||||
*************************************************************/
|
||||
void setBlinkRate(blink_type_t blink_type);
|
||||
|
||||
/*************************************************************
|
||||
Description
|
||||
Setting the brightness of matrix
|
||||
Parameter
|
||||
brightness: 0-15
|
||||
Return
|
||||
Null.
|
||||
*************************************************************/
|
||||
void setBrightness(uint8_t brightness);
|
||||
|
||||
virtual void display();
|
||||
virtual void clear();
|
||||
|
||||
protected:
|
||||
uint8_t _addr;
|
||||
};
|
||||
|
||||
|
||||
class Matrix_8x8 : public HT16K33 {
|
||||
|
||||
public:
|
||||
Matrix_8x8();
|
||||
|
||||
/*************************************************************
|
||||
Description
|
||||
Setting the display offset of x-axis and y-axis.
|
||||
This function will activate after call display().
|
||||
Parameter
|
||||
x: The display offset value of horizontal x-axis, range from -8 to 8.
|
||||
y: The display offset value of horizontal y-axis, range from -8 to 8.
|
||||
Return
|
||||
Null.
|
||||
*************************************************************/
|
||||
void setDisplayOffset(int8_t x, int8_t y);
|
||||
|
||||
/*************************************************************
|
||||
Description
|
||||
Setting the display orientation.
|
||||
This function will activate after call writeXXX().
|
||||
Parameter
|
||||
orientation: DISPLAY_ROTATE_0, DISPLAY_ROTATE_90, DISPLAY_ROTATE_180,
|
||||
DISPLAY_ROTATE_270, which means the display will rotate 0°, 90°,180° or 270°.
|
||||
Return
|
||||
Null.
|
||||
*************************************************************/
|
||||
void setDisplayOrientation(uint8_t orientation);
|
||||
|
||||
/*************************************************************
|
||||
Description
|
||||
Display the pixels stored in display buffer on 8x8 matrix.
|
||||
This function should be called after writeXXX(). And this
|
||||
function will block until all the data is shown. For example,
|
||||
if I call writeString("hello", 1000, ACTION_SCROLLING) and
|
||||
display(), then the program will block for 5 seconds(5*1000ms)
|
||||
before it goes to the next sentense.
|
||||
Parameter
|
||||
Null.
|
||||
Return
|
||||
Null.
|
||||
*************************************************************/
|
||||
void display();
|
||||
|
||||
/*************************************************************
|
||||
Description
|
||||
Clear the display buffer.
|
||||
This function will display nothing on 8x8 Matrix after call display().
|
||||
Parameter
|
||||
Null.
|
||||
Return
|
||||
Null.
|
||||
*************************************************************/
|
||||
void clear();
|
||||
|
||||
/*************************************************************
|
||||
Description
|
||||
Set a pixel ON(default) or OFF in display buffer.
|
||||
Call display() to show display buffer.
|
||||
Parameter
|
||||
x: the x-axis position of the pixel
|
||||
y: the y-axis position of the pixel
|
||||
set_on: Set the pixel ON(default) or OFF.
|
||||
Return
|
||||
Null.
|
||||
*************************************************************/
|
||||
void writePixel(uint8_t x, uint16_t y, bool set_on = true);
|
||||
|
||||
/*************************************************************
|
||||
Description
|
||||
Write a bar in display buffer.
|
||||
Call display() to show display buffer.
|
||||
Parameter
|
||||
bar: 0 - 32. 0 is blank and 32 is full.
|
||||
Return
|
||||
Null.
|
||||
*************************************************************/
|
||||
void writeBar(uint8_t bar);
|
||||
|
||||
/*************************************************************
|
||||
Description
|
||||
Write a icon in display buffer.
|
||||
Call display() to show display buffer.
|
||||
Parameter
|
||||
num: 0 - 28.
|
||||
0 full screen 1 arrow_up 2 arrow_down 3 arrow_right
|
||||
4 arrow_left 5 triangle_up 6 triangle_down 7 triangle_right
|
||||
8 triangel_left 9 smile_face_1 10 smile_face_2 11 hearts
|
||||
12 diamonds 13 clubs 14 spades 15 circle1
|
||||
16 circle2 17 circle3 18 circle4 19 man
|
||||
20 woman 21 musical_note_1 22 musical_note_2 23 snow
|
||||
24 up_down 25 double_! 26 left_right 27 house
|
||||
28 glasses
|
||||
Return
|
||||
Null.
|
||||
*************************************************************/
|
||||
void writeIcon(uint8_t num);
|
||||
|
||||
/*************************************************************
|
||||
Description
|
||||
Write a number(from -2147483648 to 2147483647) in display buffer.
|
||||
Call display() to show display buffer.
|
||||
Parameter
|
||||
number: Set the number you want to display on LED matrix. Number(except 0-9)
|
||||
will scroll horizontally, the shorter you set the ms_per_digit,
|
||||
the faster it scrolls. The number range from -2147483648 to 2147483647, if
|
||||
you want to display larger number, please use writeString().
|
||||
ms_per_digit: Set the display time(ms) of per digit.
|
||||
Return
|
||||
Null.
|
||||
*************************************************************/
|
||||
void writeNumber(int32_t number, uint16_t ms_per_digit);
|
||||
|
||||
/*************************************************************
|
||||
Description
|
||||
Write a String in display buffer.
|
||||
Call display() to show display buffer.
|
||||
Parameter
|
||||
s: A string. The string size should be less than (MAX_BIG_BUFFER_SIZE/8),
|
||||
the excess part will be ignored.
|
||||
ms_per_letter: Set the display time(ms) of per letter.
|
||||
mode: ACTION_SCROLLING: If the size of string is more than 1, scroll the string on the matrix;
|
||||
ACTION_SHIFT: If the size of string is more than 1, display the letter 1 by 1 on the matrix;
|
||||
Return
|
||||
Null.
|
||||
*************************************************************/
|
||||
void writeString(String s, uint16_t ms_per_letter, action_type_t mode);
|
||||
|
||||
/*************************************************************
|
||||
Description
|
||||
Write a picture in display buffer.
|
||||
Call display() to show display buffer.
|
||||
Parameter
|
||||
pic: A pointer of a uint8_t picture array.
|
||||
Return
|
||||
Null.
|
||||
*************************************************************/
|
||||
void writeOnePicture(const uint8_t *pic);
|
||||
|
||||
/*************************************************************
|
||||
Description
|
||||
Write a picture in display buffer.
|
||||
Call display() to show display buffer.
|
||||
Parameter
|
||||
pic: A uint64_t type 8x8 matrix picture, you can make it at
|
||||
https://xantorohara.github.io/led-matrix-editor/#
|
||||
Return
|
||||
Null.
|
||||
*************************************************************/
|
||||
void writeOnePicture(const uint64_t pic);
|
||||
|
||||
/*************************************************************
|
||||
Description
|
||||
Write many pictures in display buffer.
|
||||
Call display() to show display buffer.
|
||||
Parameter
|
||||
pic: A pointer
|
||||
pic_number: The number of pictures, should be less than (MAX_BIG_BUFFER_SIZE/8),
|
||||
the excess part will be ignored.
|
||||
ms_per_pic: Set the display time(ms) of per picture.
|
||||
mode: ACTION_SCROLLING: Scroll the pictures on the matrix;
|
||||
ACTION_SHIFT: Display the pictures 1 by 1 on the matrix;
|
||||
|
||||
Return
|
||||
Null.
|
||||
*************************************************************/
|
||||
void writePictures(const uint8_t *pic, uint8_t pic_number, uint16_t ms_per_pic, action_type_t mode);
|
||||
void writePictures(const uint64_t *pic, uint8_t pic_number, uint16_t ms_per_pic, action_type_t mode);
|
||||
|
||||
private:
|
||||
// Low1 High1 Low2 High2 ... Low8 High8
|
||||
uint8_t _buffer[16];
|
||||
uint8_t _big_buffer[MAX_BIG_BUFFER_SIZE];
|
||||
uint16_t _cursor_start, _cursor_end, _cursor_steps;
|
||||
uint16_t _ms;
|
||||
orientation_type_t _orientation;
|
||||
int8_t _offset_x, _offset_y;
|
||||
|
||||
};
|
||||
|
||||
#endif //__GROVE_LED_MATRIX_DRIVER_HT16K33__
|
@ -1,198 +0,0 @@
|
||||
/*
|
||||
Seeed_Font.h
|
||||
A font library for Grove - Grove - LED Matrix Driver(HT16K33 with 8x8 LED Matrix)
|
||||
|
||||
Copyright (c) 2018 seeed technology inc.
|
||||
Website : www.seeed.cc
|
||||
Author : Jerry Yip
|
||||
Create Time: 2018-06
|
||||
Version : 0.1
|
||||
Change Log :
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
// start at ascii 32(dec), for example, '0' = ASCII[48-32]
|
||||
const uint64_t ASCII[] = {
|
||||
0x0000000000000000, // space
|
||||
0x180018183c3c1800, // !
|
||||
0x00000000286c6c00, // "
|
||||
0x6c6cfe6cfe6c6c00, // #
|
||||
0x103c403804781000, // $
|
||||
0x60660c1830660600, // %
|
||||
0xfc66a6143c663c00, // &
|
||||
0x0000000c18181800, // '
|
||||
0x6030181818306000, // (
|
||||
0x060c1818180c0600, // )
|
||||
0x006c38fe386c0000, // *
|
||||
0x0010107c10100000, // +
|
||||
0x060c0c0c00000000, // ,
|
||||
0x0000003c00000000, // -
|
||||
0x0606000000000000, // .
|
||||
0x00060c1830600000, // /
|
||||
0x1c2222222222221c, // 0
|
||||
0x1c08080808080c08, // 1
|
||||
0x3e0408102020221c, // 2
|
||||
0x1c2220201820221c, // 3
|
||||
0x20203e2224283020, // 4
|
||||
0x1c2220201e02023e, // 5
|
||||
0x1c2222221e02221c, // 6
|
||||
0x040404081020203e, // 7
|
||||
0x1c2222221c22221c, // 8
|
||||
0x1c22203c2222221c, // 9
|
||||
0x0018180018180000, // :
|
||||
0x0c18180018180000, // ;
|
||||
0x6030180c18306000, // <
|
||||
0x00003c003c000000, // =
|
||||
0x060c1830180c0600, // >
|
||||
0x1800183860663c00, // ?
|
||||
0x003c421a3a221c00, // @
|
||||
0x0033333f33331e0c, // A
|
||||
0x003f66663e66663f, // B
|
||||
0x003c66030303663c, // C
|
||||
0x001f36666666361f, // D
|
||||
0x007f46161e16467f, // E
|
||||
0x000f06161e16467f, // F
|
||||
0x007c66730303663c, // G
|
||||
0x003333333f333333, // H
|
||||
0x001e0c0c0c0c0c1e, // I
|
||||
0x001e333330303078, // J
|
||||
0x006766361e366667, // K
|
||||
0x007f66460606060f, // L
|
||||
0x0063636b7f7f7763, // M
|
||||
0x006363737b6f6763, // N
|
||||
0x001c36636363361c, // O
|
||||
0x000f06063e66663f, // P
|
||||
0x00381e3b3333331e, // Q
|
||||
0x006766363e66663f, // R
|
||||
0x001e33380e07331e, // S
|
||||
0x001e0c0c0c0c2d3f, // T
|
||||
0x003f333333333333, // U
|
||||
0x000c1e3333333333, // V
|
||||
0x0063777f6b636363, // W
|
||||
0x0063361c1c366363, // X
|
||||
0x001e0c0c1e333333, // Y
|
||||
0x007f664c1831637f, // Z
|
||||
0x7818181818187800, // [
|
||||
0x006030180c060000, // '\'
|
||||
0x1e18181818181e00, // ]
|
||||
0x0000008244281000, // ^
|
||||
0x7e00000000000000, // _
|
||||
0x0000000060303000, // `
|
||||
0x006e333e301e0000, // a
|
||||
0x003b66663e060607, // b
|
||||
0x001e3303331e0000, // c
|
||||
0x006e33333e303038, // d
|
||||
0x001e033f331e0000, // e
|
||||
0x000f06060f06361c, // f
|
||||
0x1f303e33336e0000, // g
|
||||
0x006766666e360607, // h
|
||||
0x001e0c0c0c0e000c, // i
|
||||
0x1e33333030300030, // j
|
||||
0x0067361e36660607, // k
|
||||
0x001e0c0c0c0c0c0e, // l
|
||||
0x00636b7f7f330000, // m
|
||||
0x00333333331f0000, // n
|
||||
0x001e3333331e0000, // o
|
||||
0x0f063e66663b0000, // p
|
||||
0x78303e33336e0000, // q
|
||||
0x000f06666e3b0000, // r
|
||||
0x001f301e033e0000, // s
|
||||
0x00182c0c0c3e0c08, // t
|
||||
0x006e333333330000, // u
|
||||
0x000c1e3333330000, // v
|
||||
0x00367f7f6b630000, // w
|
||||
0x0063361c36630000, // x
|
||||
0x1f303e3333330000, // y
|
||||
0x003f260c193f0000, // z
|
||||
0x7018180c18187000, // {
|
||||
0x0008080808080800, // |
|
||||
0x0e18183018180e00, // }
|
||||
0x000000365c000000 // ~
|
||||
};
|
||||
|
||||
const uint64_t ICONS[] = {
|
||||
0xffffffffffffffff, // 0 full screen
|
||||
0x383838fe7c381000, // 1 arrow_up
|
||||
0x10387cfe38383800, // 2 arrow_down
|
||||
0x10307efe7e301000, // 3 arrow_right
|
||||
0x1018fcfefc181000, // 4 arrow_left
|
||||
0xfefe7c7c38381000, // 5 triangle_up
|
||||
0x1038387c7cfefe00, // 6 triangle_down
|
||||
0x061e7efe7e1e0600, // 7 triangle_right
|
||||
0xc0f0fcfefcf0c000, // 8 triangel_left
|
||||
0x7c92aa82aa827c00, // 9 smile_face_1
|
||||
0x003c420000660000, // 10 smile_face_2
|
||||
0x10387cfefeee4400, // 11 hearts
|
||||
0x10387cfe7c381000, // 12 diamonds
|
||||
0x381054fe54381000, // 13 clubs
|
||||
0x38107cfe7c381000, // 14 spades
|
||||
0x00387c7c7c380000, // 15 circle1
|
||||
0xffc7838383c7ffff, // 16 circle2
|
||||
0x0038444444380000, // 17 circle3
|
||||
0xffc7bbbbbbc7ffff, // 18 circle4
|
||||
0x0c12129ca0c0f000, // 19 man
|
||||
0x38444438107c1000, // 20 woman
|
||||
0x060e0c0808281800, // 21 musical_note_1
|
||||
0x066eecc88898f000, // 22 musical_note_2
|
||||
0x105438ee38541000, // 23 snow
|
||||
0x1038541054381000, // 24 up_down
|
||||
0x6666006666666600, // 25 double_!
|
||||
0x002844fe44280000, // 26 left_right
|
||||
0xfe8282c66c381000, // 27 house
|
||||
0x002400e7a5bde700 // 28 glasses
|
||||
};
|
||||
|
||||
const uint64_t BARS[] = {
|
||||
0x0000000000000000,
|
||||
0x1800000000000000,
|
||||
0x3c00000000000000,
|
||||
0x7e00000000000000,
|
||||
0xff00000000000000,
|
||||
0xff18000000000000,
|
||||
0xff3c000000000000,
|
||||
0xff7e000000000000,
|
||||
0xffff000000000000,
|
||||
0xffff180000000000,
|
||||
0xffff3c0000000000,
|
||||
0xffff7e0000000000,
|
||||
0xffffff0000000000,
|
||||
0xffffff1800000000,
|
||||
0xffffff3c00000000,
|
||||
0xffffff7e00000000,
|
||||
0xffffffff00000000,
|
||||
0xffffffff18000000,
|
||||
0xffffffff3c000000,
|
||||
0xffffffff7e000000,
|
||||
0xffffffffff000000,
|
||||
0xffffffffff180000,
|
||||
0xffffffffff3c0000,
|
||||
0xffffffffff7e0000,
|
||||
0xffffffffffff0000,
|
||||
0xffffffffffff1800,
|
||||
0xffffffffffff3c00,
|
||||
0xffffffffffff7e00,
|
||||
0xffffffffffffff00,
|
||||
0xffffffffffffff18,
|
||||
0xffffffffffffff3c,
|
||||
0xffffffffffffff7e,
|
||||
0xffffffffffffffff
|
||||
};
|
Binary file not shown.
Binary file not shown.
@ -1,13 +0,0 @@
|
||||
## Bibliothèques pour Arduino
|
||||
|
||||
### Grove_IMU_9DOF :
|
||||
- Wiki : https://wiki.seeedstudio.com/Grove-IMU_9DOF_v2.0/
|
||||
- Forge : https://github.com/Seeed-Studio/Grove_IMU_9DOF
|
||||
- Licence : MIT
|
||||
|
||||
### Grove_LED_Matrix_Driver_HT16K33 :
|
||||
- Wiki : https://wiki.seeedstudio.com/Grove-Red_LED_Matrix_w_Driver
|
||||
- Forge : https://github.com/Seeed-Studio/Grove_LED_Matrix_Driver_HT16K33
|
||||
- Outil en ligne pour générer des caractères : https://xantorohara.github.io/led-matrix-editor/#
|
||||
- Licence : MIT
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,84 @@
|
||||
#include "Wire.h"
|
||||
#include "MPU6050.h"
|
||||
|
||||
/******************************************************************************
|
||||
* 4-labyrinthe-imu.ino
|
||||
* @title: Programme pour la carte Arduino de gestion de centrale inertielle (capteur IMU)
|
||||
* @project: Blender-EduTech - Tutoriel 3 : Labyrinthe à bille - Interfacer avec une carte Arduino par la liaision série
|
||||
* @lang: fr
|
||||
* @authors: Philippe Roy <philippe.roy@ac-grenoble.fr>
|
||||
* @copyright: Copyright (C) 2023 Philippe Roy
|
||||
* @license: GNU GPL
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/******************************************************************************
|
||||
* IMU - I2C
|
||||
******************************************************************************/
|
||||
|
||||
MPU6050 accelgyro;
|
||||
|
||||
int16_t ax, ay, az;
|
||||
int16_t gx, gy, gz;
|
||||
int16_t mx, my, mz;
|
||||
float Axyz[3];
|
||||
float roll;
|
||||
float pitch;
|
||||
float roll_deg;
|
||||
float pitch_deg;
|
||||
String roll_txt;
|
||||
String pitch_txt;
|
||||
String serial_msg_int_txt;
|
||||
|
||||
/******************************************************************************
|
||||
* Communication serie
|
||||
******************************************************************************/
|
||||
|
||||
String serial_msg = ""; // Message
|
||||
|
||||
/******************************************************************************
|
||||
* Initialisation
|
||||
******************************************************************************/
|
||||
|
||||
void setup() {
|
||||
|
||||
// Liaison série
|
||||
Serial.begin(115200);
|
||||
|
||||
// IMU
|
||||
Wire.begin();
|
||||
accelgyro.initialize();
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* Boucle principale
|
||||
******************************************************************************/
|
||||
|
||||
void loop() {
|
||||
|
||||
/*****
|
||||
* Lecture des accélérations
|
||||
*****/
|
||||
|
||||
accelgyro.getMotion9(&ax, &ay, &az, &gx, &gy, &gz, &mx, &my, &mz);
|
||||
Axyz[0] = (double) ax / 16384;
|
||||
Axyz[1] = (double) ay / 16384;
|
||||
Axyz[2] = (double) az / 16384;
|
||||
roll = asin(-Axyz[0]);
|
||||
roll_deg = roll*57.3;
|
||||
roll_txt = String(roll_deg);
|
||||
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);
|
||||
|
||||
/*****
|
||||
* IMU : Arduino -> UPBGE
|
||||
*****/
|
||||
|
||||
Serial.print(roll_txt);
|
||||
Serial.print(",");
|
||||
Serial.print(pitch_txt);
|
||||
Serial.println();
|
||||
|
||||
}
|
||||
|
Binary file not shown.
@ -30,58 +30,19 @@ ACTIVATE = bge.logic.KX_INPUT_ACTIVE
|
||||
|
||||
serial_baud=115200
|
||||
# serial_comm = serial.Serial('COM4',serial_baud, timeout=0.016) # Windows
|
||||
serial_comm = serial.Serial('/dev/ttyACM1',serial_baud, timeout=0.016) # GNU/Linux
|
||||
serial_comm = serial.Serial('/dev/ttyACM0',serial_baud, timeout=0.016) # GNU/Linux
|
||||
print (serial_comm)
|
||||
|
||||
###############################################################################
|
||||
# Gestion de la centrale inertielle (capteur IMU (inertial measurement unit))
|
||||
###############################################################################
|
||||
|
||||
# Extraction d'un texte compris entre deux bornes textuelles
|
||||
def txt_extrac(txt, borne_avant, borne_apres):
|
||||
if txt.find(borne_avant)>0 and txt.find(borne_apres)>0:
|
||||
txt1 = txt.split(borne_avant, 2)
|
||||
txt2 = txt1[1].split(borne_apres, 2)
|
||||
return (txt2[0])
|
||||
else:
|
||||
return ("")
|
||||
|
||||
# Atteindre une orientation (bas niveau)
|
||||
def applyRotationTo(obj, rx=None, ry=None, rz=None, Local=True):
|
||||
rres=0.001 # Résolution rotation
|
||||
|
||||
# x
|
||||
if rx is not None:
|
||||
while (abs(rx-obj.worldOrientation.to_euler().x) > rres) :
|
||||
if obj.worldOrientation.to_euler().x-rx > rres:
|
||||
obj.applyRotation((-rres, 0, 0), Local)
|
||||
if rx-obj.worldOrientation.to_euler().x > rres:
|
||||
obj.applyRotation((rres, 0, 0), Local)
|
||||
# print ("delta x ",rx-obj.worldOrientation.to_euler().x)
|
||||
|
||||
# y
|
||||
if ry is not None:
|
||||
while (abs(ry-obj.worldOrientation.to_euler().y) > rres) :
|
||||
if obj.worldOrientation.to_euler().y-ry > rres:
|
||||
obj.applyRotation((0, -rres, 0), Local)
|
||||
if ry-obj.worldOrientation.to_euler().y > rres:
|
||||
obj.applyRotation((0, rres, 0), Local)
|
||||
# print ("delta y ",ry-obj.worldOrientation.to_euler().y)
|
||||
|
||||
# z
|
||||
if rz is not None:
|
||||
while (abs(rz-obj.worldOrientation.to_euler().z) > rres) :
|
||||
if obj.worldOrientation.to_euler().z-rz > rres:
|
||||
obj.applyRotation((0, 0, -rres), Local)
|
||||
if rz-obj.worldOrientation.to_euler().z > rres:
|
||||
obj.applyRotation((0, 0, rres), Local)
|
||||
# print ("delta z ",rz-obj.worldOrientation.to_euler().z)
|
||||
|
||||
# Lecture du capteur IMU
|
||||
def capteur(cont):
|
||||
def capteur(cont):
|
||||
obj = cont.owner # obj est l'objet associé au contrôleur donc 'Plateau'
|
||||
obj_bille = scene.objects['Bille']
|
||||
resolution = 0.2
|
||||
echelle = 0.2 # Facteur d'échelle entre la capteur et la 3D
|
||||
ecart=0.001 # Écart maxi sur la rotation
|
||||
|
||||
# Touche ESC -> Quitter
|
||||
keyboard = bge.logic.keyboard
|
||||
@ -92,14 +53,18 @@ def capteur(cont):
|
||||
# Lecture de la liaison série : programme Arduino : 3-labyrinthe-imu.ino
|
||||
serial_msg_in = str(serial_comm.readline())
|
||||
|
||||
# Roll et Pitch
|
||||
# Roulis/Roll(x) et Tangage/Pitch(y)
|
||||
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)
|
||||
applyRotationTo(scene.objects['Plateau'], x,y, 0)
|
||||
if x_txt != " NAN" and y_txt != " NAN": # NAN : Not A Number
|
||||
x=-(float(x_txt)/57.3) * echelle # 1/ 360 / (2 * pi)
|
||||
y=-(float(y_txt)/57.3) * echelle # 1/ 360 / (2 * pi)
|
||||
while abs(x-obj.worldOrientation.to_euler().x) > ecart :
|
||||
obj.applyRotation((x-obj.worldOrientation.to_euler().x, 0, -obj.worldOrientation.to_euler().z), False)
|
||||
while abs(y-obj.worldOrientation.to_euler().y) > ecart :
|
||||
obj.applyRotation((0, y-obj.worldOrientation.to_euler().y, -obj.worldOrientation.to_euler().z), False)
|
||||
|
||||
###############################################################################
|
||||
# Gameplay
|
Loading…
Reference in New Issue
Block a user