update
This commit is contained in:
87
src/main.cpp
Normal file
87
src/main.cpp
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
Script de base pour afficher un message sur une matrice LED 64x32
|
||||
*/
|
||||
#include <Arduino.h>
|
||||
#include <PxMatrix.h>
|
||||
|
||||
// Define Matrix pins for ESP32 (voir https://github.com/aircarto/ModuleAir_V2.1/blob/main/pinMap.md)
|
||||
|
||||
#define P_LAT 25
|
||||
#define P_A 17
|
||||
#define P_B 33
|
||||
#define P_C 4
|
||||
#define P_D 12
|
||||
#define P_E 15
|
||||
#define P_OE 16
|
||||
|
||||
hw_timer_t * timer = NULL;
|
||||
portMUX_TYPE timerMux = portMUX_INITIALIZER_UNLOCKED;
|
||||
|
||||
//define matrix size
|
||||
#define matrix_width 64
|
||||
#define matrix_height 32
|
||||
|
||||
uint8_t display_draw_time = 30; //10-50 is usually fine
|
||||
PxMATRIX display(64, 32, P_LAT, P_OE, P_A, P_B, P_C, P_D, P_E);
|
||||
|
||||
//Need this two functions for ESP32 to refresh display
|
||||
void IRAM_ATTR display_updater()
|
||||
{
|
||||
// Increment the counter and set the time of ISR
|
||||
portENTER_CRITICAL_ISR(&timerMux);
|
||||
display.display(display_draw_time);
|
||||
portEXIT_CRITICAL_ISR(&timerMux);
|
||||
}
|
||||
|
||||
void display_update_enable(bool is_enable)
|
||||
{
|
||||
Serial.print("Call display_update_enable function with:");
|
||||
if (is_enable)
|
||||
{
|
||||
Serial.println("true");
|
||||
//timer = timerBegin(0, 80, true);
|
||||
timerAttachInterrupt(timer, &display_updater, true);
|
||||
timerAlarmWrite(timer, 4000, true);
|
||||
timerAlarmEnable(timer);
|
||||
}
|
||||
else
|
||||
{
|
||||
Serial.println("false");
|
||||
timerDetachInterrupt(timer);
|
||||
timerAlarmDisable(timer);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
SETUP AND LOOP
|
||||
*/
|
||||
|
||||
void setup() {
|
||||
// put your setup code here, to run once:
|
||||
Serial.begin(115200);
|
||||
Serial.println("Hello, Arduino!");
|
||||
display.begin(8);
|
||||
display.setFastUpdate(true);
|
||||
|
||||
// ⭐ INITIALISER LE TIMER ICI ⭐
|
||||
timer = timerBegin(0, 80, true); // Timer 0, prescaler 80, count up
|
||||
timerAlarmWrite(timer, 4000, true); // Interruption toutes les 4ms
|
||||
|
||||
// Activer le rafraîchissement
|
||||
display_update_enable(true);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// put your main code here, to run repeatedly:
|
||||
Serial.println("Showing message on LED matrix");
|
||||
|
||||
display.fillScreen(0); // Clear the display
|
||||
display.setCursor(1, 1);
|
||||
display.setTextColor(display.color565(0, 255, 0));
|
||||
display.setTextSize(1);
|
||||
display.print("Hello");
|
||||
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user