Code arduino 240V lettres 2 colonnes
#include <DIO2.h>
#define DEBUG false
#define COL_NB 2
#define LIN_NB 7
int pin_col[COL_NB] = {3, 2};
int pin_lin[LIN_NB] = {4, 5, 6, 7, 8, 9, 10};
int seg[2][7] = { {0, 1, 0, 1, 0, 0, 0},{1, 0, 1, 0, 1, 0, 0} };
//AC
#define pinACsense A0
int last_AC_detect = LOW;
void setup() {
//AC
pinMode2(pinACsense, INPUT);
pinMode2(LED_BUILTIN, OUTPUT);
for (int i = 0; i < COL_NB; i++) {
pinMode2(pin_col[i], OUTPUT);
}
for (int i = 0; i < LIN_NB; i++) {
pinMode2(pin_lin[i], OUTPUT);
}
if (DEBUG) Serial.begin(115200);
if (DEBUG) Serial.println("let's rock!");
}
int letter[7];
void loop() {
//int digitNb = ((long)millis / 1000) % 2;
// COLONNES < 2
for (int j = 0; j < 2; j++) {
// copy current letter
/*
for (int k = 0; k < 7; k++) {
letter[k] = seg[j][k];
if (DEBUG) Serial.print(letter[k]);
if (DEBUG) Serial.print("\t");
}
if (DEBUG) Serial.println("");
*/
////////////////////
// allume une colonne
int b = pin_col[j];
digitalWrite2(b, HIGH);
// LIGNES < 7
for (int i = 0; i < 7; i++) {
int a = pin_lin[i];
//if (letter[i] == 1) {
if (seg[j][i] == 1) {
digitalWrite2(a, HIGH);
if (DEBUG) Serial.print("HIGH");
}
else {
digitalWrite2(a, LOW);
if (DEBUG) Serial.print("LOW");
}
if (DEBUG) Serial.println("");
} // end lines
// persistence retinienne (env 40ms)
delayMicroseconds(9000);
// Wait for AC sync...
int AC_detect = LOW;
while ( AC_detect != HIGH) {
AC_detect = digitalRead2(pinACsense);
}
// cols down
digitalWrite2(b, LOW);
// lines down
for (int t = 0; t < 7; t++) {
int z = pin_lin[t];
digitalWrite2(z, LOW);
}
} // end cols
}
Code arduino 240V led matrix test simple
#define COL_NB 2
#define LIN_NB 7
int pin_col[COL_NB] = {2, 3};
int pin_lin[LIN_NB] = {4, 5, 6, 7, 8, 9, 10};
void setup() {
for (int i = 0; i < COL_NB; i++) {
pinMode(pin_col[i], OUTPUT);
}
for (int i = 0; i < LIN_NB; i++) {
pinMode(pin_lin[i], OUTPUT);
}
Serial.begin(114200);
Serial.println("let's rock!");
}
void loop() {
for (int i = 0; i < 2; i++) {
int a = random(2) + 2;
//int a=pin_col[i];
digitalWrite(a, HIGH);
Serial.print("col= ");
Serial.println(a);
for (int j = 0; j < LIN_NB; j++) {
int b = random(7) + 4;
//int a=pin_lin[j];
digitalWrite(b, HIGH);
Serial.print("line= ");
Serial.println(pin_lin[j]);
delay(50);
random(5)==0?digitalWrite(b, LOW):digitalWrite(b, HIGH);
}
digitalWrite(a, LOW);
/*
for (int j = 0; j < LIN_NB; j++) {
//digitalWrite(pin_lin[j], HIGH);
Serial.print("line= ");
Serial.println(pin_lin[j]);
delay(10);
digitalWrite(pin_lin[j], LOW);
}
digitalWrite(pin_col[i], LOW);
*/
}
}
Code arduino 240V led matrix with AC sensing and FastIO
#include <DIO2.h>
#define COL_NB 2
#define LIN_NB 7
int pin_col[COL_NB] = {2, 3};
int pin_lin[LIN_NB] = {4, 5, 6, 7, 8, 9, 10};
//AC
#define pinACsense A0
int last_AC_detect = LOW;
void setup() {
//AC
pinMode2(pinACsense, INPUT);
pinMode2(LED_BUILTIN, OUTPUT);
for (int i = 0; i < COL_NB; i++) {
pinMode2(pin_col[i], OUTPUT);
}
for (int i = 0; i < LIN_NB; i++) {
pinMode2(pin_lin[i], OUTPUT);
}
//Serial.begin(114200);
//Serial.println("let's rock!");
}
int intensity_time = 0;
int step = 40;
// bool back_from_last_scan = false;
void loop() {
// LIGNES < 7
for (int i = 0; i < 4; i++) {
/*
int AC_detect = LOW;
// Wait for AC sync...
while ( AC_detect != HIGH || back_from_last_scan) {
AC_detect = digitalRead(pinACsense);
}
*/
int a = pin_lin[i];
digitalWrite2(a, HIGH);
// COLONNES < 2
for (int j = 0; j < 2; j++) {
int b = pin_col[j];
digitalWrite2(b, HIGH);
}
int AC_detect = LOW;
// Wait for AC sync...
while ( AC_detect != HIGH) {
AC_detect = digitalRead2(pinACsense);
}
//delayMicroseconds(9000);
/*
delayMicroseconds(intensity_time);
intensity_time += step;
if(abs(intensity_time) > 9000) step=-step;
*/
// ligne down
digitalWrite2(a, LOW);
// cols down
for (int j = 0; j < 2; j++) {
int b = pin_col[j];
digitalWrite2(b, LOW);
}
// back_from_last_scan = true;
}
}