Bonjour à tous,
J'ai récupérer un code sur une application android "arduino works" pour faire un countdown timer.
La compilation et le televersement se fait correctement mais rien ne fonctionne.
composition du projet : module led matrix 32x8 , arduino nano et 3 inter.
je met le code, le plan de cablage et les fichiers ci-dessous
si qqun voit un problème quelque part
merci
#include <LEDMatrixDriver.hpp>
#include "SystemFont3x7.h"
// Font constant
//-------------------------------
#define FONT_LENGTH 0
#define FONT_FIXED_WIDTH 2
#define FONT_HEIGHT 3
#define FONT_FIRST_CHAR 4
#define FONT_CHAR_COUNT 5
#define FONT_WIDTH_TABLE 6
//-------------------------------
// pin definition
#define PIN_BUZZER 6
#define PIN_10SEC 2
#define PIN_5MIN 3
#define PIN_START 4
#define LEDMATRIX_CS_PIN 12
// Number of 8x8 segments you are connecting
const int LEDMATRIX_SEGMENTS = 4;
const int LEDMATRIX_WIDTH = LEDMATRIX_SEGMENTS * 8;
// The LEDMatrixDriver class instance
LEDMatrixDriver matrix(LEDMATRIX_SEGMENTS, LEDMATRIX_CS_PIN);
unsigned long startTime ;
unsigned long elapseTime ;
unsigned long countDown=0;
bool bCountDown = false;
//==================================================
void setup()
{
Serial.begin(9600);
pinMode(PIN_BUZZER, OUTPUT);
pinMode(PIN_10SEC, INPUT_PULLUP);
pinMode(PIN_5MIN, INPUT_PULLUP);
pinMode(PIN_START, INPUT_PULLUP);
// init the display
matrix.setEnabled(true);
matrix.setIntensity(2); // 0 = low, 10 = high
matrix.clear();
draw_string(2,1, System3x7, "00:00");
matrix.display();
}
//==================================================
void draw_buffer ( int x, int y ,const uint8_t *font, uint16_t font_index, byte width )
{
int height =8;
byte mask ;
byte val;
for( int dx = 0; dx < width; dx++ )
{
val = pgm_read_byte(font + font_index + dx);
mask = B00000001;
for( int dy = 0; dy < height; dy++ )
{
if (x+dx >=LEDMATRIX_WIDTH)
continue;
if (y+dy >=8) // height is 8
continue;
matrix.setPixel(x + dx, y + dy, (bool)(val & mask ));
// shift the mask by one pixel to the right
mask = mask << 1;
}
}
}
//==============================================================
byte draw_char(int x, int y, const uint8_t *font, char ch)
{
byte width;
uint16_t index = 0;
uint8_t firstChar = pgm_read_byte(font + FONT_FIRST_CHAR);
uint8_t charCount = pgm_read_byte(font + FONT_CHAR_COUNT);
if (ch < firstChar || ch >= (firstChar + charCount))
return 0; // outside the font
// fixed width
if (pgm_read_byte(font + FONT_LENGTH) == 0
&& pgm_read_byte(font + FONT_LENGTH + 1) == 0)
{
// zero length is flag indicating fixed width font (array does not contain width data entries)
width = pgm_read_byte(font + FONT_FIXED_WIDTH);
index = (ch-firstChar) * width + FONT_WIDTH_TABLE;
}
else
{
width = pgm_read_byte(font + FONT_WIDTH_TABLE + (ch-firstChar));
// variable width font, read width data, to get the index
for (uint8_t i = firstChar; i < ch; i++)
{
index += pgm_read_byte(font + FONT_WIDTH_TABLE + (i-firstChar));
}
index += charCount + FONT_WIDTH_TABLE ;
}
draw_buffer( x, y,font, index, width);
return width;
}
//====================================================
void draw_string(int x, int y, const uint8_t *font, String str)
{
int x1 = x;
for (int i =0; i<str.length(); i++)
{
x1 += draw_char(x1, y, font, str.charAt(i)) + 1; // 1 px spacing
}
}
//====================================================
void show_countdown()
{
if (countDown > 60* 60)
countDown = 0;
int mm = countDown/60;
int ss = countDown - mm*60;
char buf[6];
matrix.clear();
sprintf(buf,"%02d:%02d", mm,ss);
draw_string(2,1, System3x7, buf);
matrix.display();
}
//====================================================
void loop()
{
int minute=0, second=0, ms=0;
if (bCountDown)
{
matrix.display();
elapseTime = millis() - startTime;
if (countDown*1000 > elapseTime)
{
elapseTime = countDown*1000 - elapseTime ;
int totalsecond = elapseTime /1000;
minute = totalsecond / 60;
second = totalsecond - 60 * minute ;
ms = elapseTime - totalsecond*1000;
}
else // reach
{
minute = 0; second = 0 ; ms = 0;
bCountDown = false;
}
char buf[9];
matrix.clear();
sprintf(buf,"%02d:%02d.%01d",minute, second,(int)(ms/100 ) );
draw_string(2,1, System3x7, buf);
matrix.display();
if (!bCountDown)
{
tone(PIN_BUZZER, 400, 500); delay(2000);
tone(PIN_BUZZER, 400, 500); delay(2000);
tone(PIN_BUZZER, 400, 500); delay(2000);
noTone(PIN_BUZZER);
}
}
else // setup countdown time
{
if (digitalRead(PIN_10SEC)==LOW)
{
delay(50);
while (digitalRead(PIN_10SEC)==LOW);
delay(50);
countDown += 10;
show_countdown();
}
if (digitalRead(PIN_5MIN)==LOW)
{
delay(50);
while (digitalRead(PIN_5MIN)==LOW);
delay(50);
countDown += 5 * 60 - (countDown %300) ;
show_countdown();
}
if (digitalRead(PIN_START)==LOW)
{
delay(50);
while (digitalRead(PIN_START)==LOW);
delay(50);
bCountDown = true;
startTime = millis();
}
}
}
arduino_matrix4_countdown.zip (23,2 Ko)