Picture to attract attentionThe other day there was a side job, an order was received to record a sketch on arduino. Simple but voluminous. With repeating blocks. It was necessary to control each port of the Arduino Mega separately, when receiving a command on the Uart. You send a symbol - and the LED (for example) lights up for a certain time. I wrote a sketch for 2 teams, threw off the customer for tests, received an advance payment. Further, it was necessary to scale to all ports.
For a start, I honestly tried with my hands. Having written the first 26 # define, the enthusiasm has dried up. I went to get some fresh air, and remembered that on my PC (Win 7 x64), Python 3.6 from the
Anaconda distribution was already installed. By the way, this is the most convenient way to install Python on Windows, since everything is already included and configured by default, and there is a package manager.
')
So let's get started.
Create a folder with an empty file in it, I called it "arduino_gen.py" and the bat file "start_py.bat" with the following contents:
python.exe arduino_gen.py > code_out.txt
@pause
We will need this file to run the program in Python.
Now we will write a program that will generate us the necessary code for the Arduino.
To begin with, we will create two
lists with all the values we need, which we will substitute into the code. Names can be any matter of taste.
chap = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'] num = ['2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31','32','33','34','35','36','37','38','39','40','41','42','43','44','45','46','47','48','49','50','51','52','53']
And two variables to iterate through lists.
i = 0 k = 0
And now let's create a loop to generate #define PIN_a 2 ... #define PIN_Z 53
iteration1 = True while iteration1: print('#define PIN_' + chap[i] + ' ' + num[k]) i = i + 1 k = k + 1 if i > 51: iteration1 = False print()
Save, run the file "start_py.bat"
result #define PIN_a 2 #define PIN_b 3 #define PIN_c 4 #define PIN_d 5 #define PIN_e 6 #define PIN_f 7 #define PIN_g 8 #define PIN_h 9 #define PIN_i 10 #define PIN_j 11 #define PIN_k 12 #define PIN_l 13 #define PIN_m 14 #define PIN_n 15 #define PIN_o 16 #define PIN_p 17 #define PIN_q 18 #define PIN_r 19 #define PIN_s 20 #define PIN_t 21 #define PIN_u 22 #define PIN_v 23 #define PIN_w 24 #define PIN_x 25 #define PIN_y 26 #define PIN_z 27 #define PIN_A 28 #define PIN_B 29 #define PIN_C 30 #define PIN_D 31 #define PIN_E 32 #define PIN_F 33 #define PIN_G 34 #define PIN_H 35 #define PIN_I 36 #define PIN_J 37 #define PIN_K 38 #define PIN_L 39 #define PIN_M 40 #define PIN_N 41 #define PIN_O 42 #define PIN_P 43 #define PIN_Q 44 #define PIN_R 45 #define PIN_S 46 #define PIN_T 47 #define PIN_U 48 #define PIN_V 49 #define PIN_W 50 #define PIN_X 51 #define PIN_Y 52 #define PIN_Z 53
If we want to output the result immediately to a file, then we add:
python.exe arduino_gen.py > code_out.txt
@pause
As a result, we get the file “code_out.txt” from which it is convenient to copy the code into the sketch in the best traditions of Arduino.
Already at this stage, I wondered if the Arduino had enough memory if it generated a large number of variables. However, looking ahead, I will say that the memory was quite enough, as can be seen about the compilation of the sketch.

Next, I will give the rest of the code, which is easy to understand. But, for a start, consider
Simplified sketch // #define PIN_a 2 #define PIN_b 3 // #define TIME_a 10000 #define TIME_b 10000 // boolean ledState_a = false; boolean ledState_b = false; int time_a = 0; int time_b = 0; void setup() { // Serial.begin(9600); for (int i = 2; i <= 53; i++) pinMode(i, OUTPUT); } void loop() { if (Serial.available() >0) { int x = Serial.read(); //a if(x == 'a'){ ledState_a = true; time_a = TIME_a; x = 0; } //b if(x == 'b'){ ledState_b = true; time_b = TIME_b; x = 0; } } // //a if(ledState_a == true){ time_a = time_a - 1; digitalWrite(PIN_a, HIGH); } if(time_a == 0){ ledState_a = false; } if(ledState_a == false){ digitalWrite(PIN_a, LOW); } //b if(ledState_b == true){ time_b = time_b - 1; } if(time_b > 0){ digitalWrite(PIN_b, HIGH); } if(time_b == 0){ digitalWrite(PIN_b, LOW); ledState_b = false; } // delay(1); }
Here, you need to generate 4 blocks of code at the beginning. And two blocks at the end. Subsequently, the customer wanted to change the logic of the work, so that when the capital letter arrives, the output state changes. I rewrote the code section:
// - //A if(x == 'A'){ digitalWrite (PIN_A, !digitalRead(PIN_A)); x = 0; }
And scaled with Python
i = 26 iteration7 = True while iteration7: print() print('//' + chap[i]) print("if(x == '" + chap[i] + "'){") print(' digitalWrite (PIN_' + chap[i] + ', !digitalRead(PIN_' + chap[i] + '));') print(' x = 0;') print(' }') i = i + 1 if i > 51: iteration7 = False print() print('}') print()
That is what happened in the end.
Very long code, I warned!// Set Pins
#define PIN_a 2
#define PIN_b 3
#define PIN_c 4
#define PIN_d 5
#define PIN_e 6
#define PIN_f 7
#define PIN_g 8
#define PIN_h 9
#define PIN_i 10
#define PIN_j 11
#define PIN_k 12
#define PIN_l 13
#define PIN_m 14
#define PIN_n 15
#define PIN_o 16
#define PIN_p 17
#define PIN_q 18
#define PIN_r 19
#define PIN_s 20
#define PIN_t 21
#define PIN_u 22
#define PIN_v 23
#define PIN_w 24
#define PIN_x 25
#define PIN_y 26
#define PIN_z 27
#define PIN_A 28
#define PIN_B 29
#define PIN_C 30
#define PIN_D 31
#define PIN_E 32
#define PIN_F 33
#define PIN_G 34
#define PIN_H 35
#define PIN_I 36
#define PIN_J 37
#define PIN_K 38
#define PIN_L 39
#define PIN_M 40
#define PIN_N 41
#define PIN_O 42
#define PIN_P 43
#define PIN_Q 44
#define PIN_R 45
#define PIN_S 46
#define PIN_T 47
#define PIN_U 48
#define PIN_V 49
#define PIN_W 50
#define PIN_X 51
#define PIN_Y 52
#define PIN_Z 53
// Set the time
// Most likely, an amendment will be required here.
// For example, 1 second may not be 1000, but 865, for example.
// It will be necessary to measure with a stopwatch, and, if necessary,
// reduce by some coefficient
#define TIME_a 1000
#define TIME_b 1000
#define TIME_c 1000
#define TIME_d 1000
#define TIME_e 1000
#define TIME_f 1000
#define TIME_g 1000
#define TIME_h 1000
#define TIME_i 1000
#define TIME_j 1000
#define TIME_k 1000
#define TIME_l 1000
#define TIME_m 1000
#define TIME_n 1000
#define TIME_o 1000
#define TIME_p 1000
#define TIME_q 1000
#define TIME_r 1000
#define TIME_s 1000
#define TIME_t 1000
#define TIME_u 1000
#define TIME_v 1000
#define TIME_w 1000
#define TIME_x 1000
#define TIME_y 1000
#define TIME_z 1000
#define TIME_A 1000
#define TIME_B 1000
#define TIME_C 1000
#define TIME_D 1000
#define TIME_E 1000
#define TIME_F 1000
#define TIME_G 1000
#define TIME_H 1000
#define TIME_I 1000
#define TIME_J 1000
#define TIME_K 1000
#define TIME_L 1000
#define TIME_M 1000
#define TIME_N 1000
#define TIME_O 1000
#define TIME_P 1000
#define TIME_Q 1000
#define TIME_R 1000
#define TIME_S 1000
#define TIME_T 1000
#define TIME_U 1000
#define TIME_V 1000
#define TIME_W 1000
#define TIME_X 1000
#define TIME_Y 1000
#define TIME_Z 1000
// logical state of the LED (yes / no)
boolean ledState_a = false;
boolean ledState_b = false;
boolean ledState_c = false;
boolean ledState_d = false;
boolean ledState_e = false;
boolean ledState_f = false;
boolean ledState_g = false;
boolean ledState_h = false;
boolean ledState_i = false;
boolean ledState_j = false;
boolean ledState_k = false;
boolean ledState_l = false;
boolean ledState_m = false;
boolean ledState_n = false;
boolean ledState_o = false;
boolean ledState_p = false;
boolean ledState_q = false;
boolean ledState_r = false;
boolean ledState_s = false;
boolean ledState_t = false;
boolean ledState_u = false;
boolean ledState_v = false;
boolean ledState_w = false;
boolean ledState_x = false;
boolean ledState_y = false;
boolean ledState_z = false;
boolean ledState_A = false;
boolean ledState_B = false;
boolean ledState_C = false;
boolean ledState_D = false;
boolean ledState_E = false;
boolean ledState_F = false;
boolean ledState_G = false;
boolean ledState_H = false;
boolean ledState_I = false;
boolean ledState_J = false;
boolean ledState_K = false;
boolean ledState_L = false;
boolean ledState_M = false;
boolean ledState_N = false;
boolean ledState_O = false;
boolean ledState_P = false;
boolean ledState_Q = false;
boolean ledState_R = false;
boolean ledState_S = false;
boolean ledState_T = false;
boolean ledState_U = false;
boolean ledState_V = false;
boolean ledState_W = false;
boolean ledState_X = false;
boolean ledState_Y = false;
boolean ledState_Z = false;
// Variables for storing time
int time_a = 0;
int time_b = 0;
int time_c = 0;
int time_d = 0;
int time_e = 0;
int time_f = 0;
int time_g = 0;
int time_h = 0;
int time_i = 0;
int time_j = 0;
int time_k = 0;
int time_l = 0;
int time_m = 0;
int time_n = 0;
int time_o = 0;
int time_p = 0;
int time_q = 0;
int time_r = 0;
int time_s = 0;
int time_t = 0;
int time_u = 0;
int time_v = 0;
int time_w = 0;
int time_x = 0;
int time_y = 0;
int time_z = 0;
int time_A = 0;
int time_B = 0;
int time_C = 0;
int time_D = 0;
int time_E = 0;
int time_F = 0;
int time_G = 0;
int time_H = 0;
int time_I = 0;
int time_J = 0;
int time_K = 0;
int time_L = 0;
int time_M = 0;
int time_N = 0;
int time_O = 0;
int time_P = 0;
int time_Q = 0;
int time_R = 0;
int time_S = 0;
int time_T = 0;
int time_U = 0;
int time_V = 0;
int time_W = 0;
int time_X = 0;
int time_Y = 0;
int time_Z = 0;
void setup () {
// did not begin to rewrite initialization
Serial.begin (9600);
for (int i = 2; i <= 53; i ++)
pinMode (i, OUTPUT);
}
void loop () {
if (Serial.available ()> 0) {
int x = Serial.read ();
// Check that we have arrived
// a
if (x == 'a') {
ledState_a = true;
time_a = TIME_a;
x = 0;
}
// b
if (x == 'b') {
ledState_b = true;
time_b = TIME_b;
x = 0;
}
// c
if (x == 'c') {
ledState_c = true;
time_c = TIME_c;
x = 0;
}
// d
if (x == 'd') {
ledState_d = true;
time_d = TIME_d;
x = 0;
}
// e
if (x == 'e') {
ledState_e = true;
time_e = TIME_e;
x = 0;
}
// f
if (x == 'f') {
ledState_f = true;
time_f = TIME_f;
x = 0;
}
// g
if (x == 'g') {
ledState_g = true;
time_g = TIME_g;
x = 0;
}
// h
if (x == 'h') {
ledState_h = true;
time_h = TIME_h;
x = 0;
}
// i
if (x == 'i') {
ledState_i = true;
time_i = TIME_i;
x = 0;
}
// j
if (x == 'j') {
ledState_j = true;
time_j = TIME_j;
x = 0;
}
// k
if (x == 'k') {
ledState_k = true;
time_k = TIME_k;
x = 0;
}
// l
if (x == 'l') {
ledState_l = true;
time_l = TIME_l;
x = 0;
}
// m
if (x == 'm') {
ledState_m = true;
time_m = TIME_m;
x = 0;
}
// n
if (x == 'n') {
ledState_n = true;
time_n = TIME_n;
x = 0;
}
// o
if (x == 'o') {
ledState_o = true;
time_o = TIME_o;
x = 0;
}
// p
if (x == 'p') {
ledState_p = true;
time_p = TIME_p;
x = 0;
}
// q
if (x == 'q') {
ledState_q = true;
time_q = TIME_q;
x = 0;
}
// r
if (x == 'r') {
ledState_r = true;
time_r = TIME_r;
x = 0;
}
// s
if (x == 's') {
ledState_s = true;
time_s = TIME_s;
x = 0;
}
// t
if (x == 't') {
ledState_t = true;
time_t = TIME_t;
x = 0;
}
// u
if (x == 'u') {
ledState_u = true;
time_u = TIME_u;
x = 0;
}
// v
if (x == 'v') {
ledState_v = true;
time_v = TIME_v;
x = 0;
}
// w
if (x == 'w') {
ledState_w = true;
time_w = TIME_w;
x = 0;
}
// x
if (x == 'x') {
ledState_x = true;
time_x = TIME_x;
x = 0;
}
// y
if (x == 'y') {
ledState_y = true;
time_y = TIME_y;
x = 0;
}
// z
if (x == 'z') {
ledState_z = true;
time_z = TIME_z;
x = 0;
}
// When a big letter comes - change the state
// A
if (x == 'A') {
digitalWrite (PIN_A,! digitalRead (PIN_A));
x = 0;
}
// B
if (x == 'B') {
digitalWrite (PIN_B,! digitalRead (PIN_B));
x = 0;
}
// C
if (x == 'C') {
digitalWrite (PIN_C,! digitalRead (PIN_C));
x = 0;
}
// D
if (x == 'D') {
digitalWrite (PIN_D,! digitalRead (PIN_D));
x = 0;
}
// E
if (x == 'E') {
digitalWrite (PIN_E,! digitalRead (PIN_E));
x = 0;
}
// F
if (x == 'F') {
digitalWrite (PIN_F,! digitalRead (PIN_F));
x = 0;
}
// G
if (x == 'G') {
digitalWrite (PIN_G,! digitalRead (PIN_G));
x = 0;
}
// H
if (x == 'H') {
digitalWrite (PIN_H,! digitalRead (PIN_H));
x = 0;
}
// I
if (x == 'I') {
digitalWrite (PIN_I,! digitalRead (PIN_I));
x = 0;
}
// j
if (x == 'J') {
digitalWrite (PIN_J,! digitalRead (PIN_J));
x = 0;
}
// K
if (x == 'K') {
digitalWrite (PIN_K,! digitalRead (PIN_K));
x = 0;
}
// L
if (x == 'L') {
digitalWrite (PIN_L,! digitalRead (PIN_L));
x = 0;
}
// M
if (x == 'M') {
digitalWrite (PIN_M,! digitalRead (PIN_M));
x = 0;
}
// n
if (x == 'N') {
digitalWrite (PIN_N,! digitalRead (PIN_N));
x = 0;
}
// o
if (x == 'O') {
digitalWrite (PIN_O,! digitalRead (PIN_O));
x = 0;
}
// P
if (x == 'P') {
digitalWrite (PIN_P,! digitalRead (PIN_P));
x = 0;
}
// Q
if (x == 'Q') {
digitalWrite (PIN_Q,! digitalRead (PIN_Q));
x = 0;
}
// R
if (x == 'R') {
digitalWrite (PIN_R,! digitalRead (PIN_R));
x = 0;
}
// s
if (x == 'S') {
digitalWrite (PIN_S,! digitalRead (PIN_S));
x = 0;
}
// T
if (x == 'T') {
digitalWrite (PIN_T,! digitalRead (PIN_T));
x = 0;
}
// U
if (x == 'U') {
digitalWrite (PIN_U,! digitalRead (PIN_U));
x = 0;
}
// v
if (x == 'V') {
digitalWrite (PIN_V,! digitalRead (PIN_V));
x = 0;
}
// W
if (x == 'W') {
digitalWrite (PIN_W,! digitalRead (PIN_W));
x = 0;
}
// X
if (x == 'X') {
digitalWrite (PIN_X,! digitalRead (PIN_X));
x = 0;
}
// Y
if (x == 'Y') {
digitalWrite (PIN_Y,! digitalRead (PIN_Y));
x = 0;
}
// z
if (x == 'Z') {
digitalWrite (PIN_Z,! digitalRead (PIN_Z));
x = 0;
}
}
// a
if (ledState_a == true) {
time_a = time_a - 1;
digitalWrite (PIN_a, HIGH);
}
if (time_a == 0) {
ledState_a = false;
}
if (ledState_a == false) {
digitalWrite (PIN_a, LOW);
}
// b
if (ledState_b == true) {
time_b = time_b - 1;
digitalWrite (PIN_b, HIGH);
}
if (time_b == 0) {
ledState_b = false;
}
if (ledState_b == false) {
digitalWrite (PIN_b, LOW);
}
// c
if (ledState_c == true) {
time_c = time_c - 1;
digitalWrite (PIN_c, HIGH);
}
if (time_c == 0) {
ledState_c = false;
}
if (ledState_c == false) {
digitalWrite (PIN_c, LOW);
}
// d
if (ledState_d == true) {
time_d = time_d - 1;
digitalWrite (PIN_d, HIGH);
}
if (time_d == 0) {
ledState_d = false;
}
if (ledState_d == false) {
digitalWrite (PIN_d, LOW);
}
// e
if (ledState_e == true) {
time_e = time_e - 1;
digitalWrite (PIN_e, HIGH);
}
if (time_e == 0) {
ledState_e = false;
}
if (ledState_e == false) {
digitalWrite (PIN_e, LOW);
}
// f
if (ledState_f == true) {
time_f = time_f - 1;
digitalWrite (PIN_f, HIGH);
}
if (time_f == 0) {
ledState_f = false;
}
if (ledState_f == false) {
digitalWrite (PIN_f, LOW);
}
// g
if (ledState_g == true) {
time_g = time_g - 1;
digitalWrite (PIN_g, HIGH);
}
if (time_g == 0) {
ledState_g = false;
}
if (ledState_g == false) {
digitalWrite (PIN_g, LOW);
}
// h
if (ledState_h == true) {
time_h = time_h - 1;
digitalWrite (PIN_h, HIGH);
}
if (time_h == 0) {
ledState_h = false;
}
if (ledState_h == false) {
digitalWrite (PIN_h, LOW);
}
// i
if (ledState_i == true) {
time_i = time_i - 1;
digitalWrite (PIN_i, HIGH);
}
if (time_i == 0) {
ledState_i = false;
}
if (ledState_i == false) {
digitalWrite (PIN_i, LOW);
}
// j
if (ledState_j == true) {
time_j = time_j - 1;
digitalWrite (PIN_j, HIGH);
}
if (time_j == 0) {
ledState_j = false;
}
if (ledState_j == false) {
digitalWrite (PIN_j, LOW);
}
// k
if (ledState_k == true) {
time_k = time_k - 1;
digitalWrite (PIN_k, HIGH);
}
if (time_k == 0) {
ledState_k = false;
}
if (ledState_k == false) {
digitalWrite (PIN_k, LOW);
}
// l
if (ledState_l == true) {
time_l = time_l - 1;
digitalWrite (PIN_l, HIGH);
}
if (time_l == 0) {
ledState_l = false;
}
if (ledState_l == false) {
digitalWrite (PIN_l, LOW);
}
// m
if (ledState_m == true) {
time_m = time_m - 1;
digitalWrite (PIN_m, HIGH);
}
if (time_m == 0) {
ledState_m = false;
}
if (ledState_m == false) {
digitalWrite (PIN_m, LOW);
}
// n
if (ledState_n == true) {
time_n = time_n - 1;
digitalWrite (PIN_n, HIGH);
}
if (time_n == 0) {
ledState_n = false;
}
if (ledState_n == false) {
digitalWrite (PIN_n, LOW);
}
// o
if (ledState_o == true) {
time_o = time_o - 1;
digitalWrite (PIN_o, HIGH);
}
if (time_o == 0) {
ledState_o = false;
}
if (ledState_o == false) {
digitalWrite (PIN_o, LOW);
}
// p
if (ledState_p == true) {
time_p = time_p - 1;
digitalWrite (PIN_p, HIGH);
}
if (time_p == 0) {
ledState_p = false;
}
if (ledState_p == false) {
digitalWrite (PIN_p, LOW);
}
// q
if (ledState_q == true) {
time_q = time_q - 1;
digitalWrite (PIN_q, HIGH);
}
if (time_q == 0) {
ledState_q = false;
}
if (ledState_q == false) {
digitalWrite (PIN_q, LOW);
}
// r
if (ledState_r == true) {
time_r = time_r - 1;
digitalWrite (PIN_r, HIGH);
}
if (time_r == 0) {
ledState_r = false;
}
if (ledState_r == false) {
digitalWrite (PIN_r, LOW);
}
// s
if (ledState_s == true) {
time_s = time_s - 1;
digitalWrite (PIN_s, HIGH);
}
if (time_s == 0) {
ledState_s = false;
}
if (ledState_s == false) {
digitalWrite (PIN_s, LOW);
}
// t
if (ledState_t == true) {
time_t = time_t - 1;
digitalWrite (PIN_t, HIGH);
}
if (time_t == 0) {
ledState_t = false;
}
if (ledState_t == false) {
digitalWrite (PIN_t, LOW);
}
// u
if (ledState_u == true) {
time_u = time_u - 1;
digitalWrite (PIN_u, HIGH);
}
if (time_u == 0) {
ledState_u = false;
}
if (ledState_u == false) {
digitalWrite (PIN_u, LOW);
}
// v
if (ledState_v == true) {
time_v = time_v - 1;
digitalWrite (PIN_v, HIGH);
}
if (time_v == 0) {
ledState_v = false;
}
if (ledState_v == false) {
digitalWrite (PIN_v, LOW);
}
// w
if (ledState_w == true) {
time_w = time_w - 1;
digitalWrite (PIN_w, HIGH);
}
if (time_w == 0) {
ledState_w = false;
}
if (ledState_w == false) {
digitalWrite (PIN_w, LOW);
}
// x
if (ledState_x == true) {
time_x = time_x - 1;
digitalWrite (PIN_x, HIGH);
}
if (time_x == 0) {
ledState_x = false;
}
if (ledState_x == false) {
digitalWrite (PIN_x, LOW);
}
// y
if (ledState_y == true) {
time_y = time_y - 1;
digitalWrite (PIN_y, HIGH);
}
if (time_y == 0) {
ledState_y = false;
}
if (ledState_y == false) {
digitalWrite (PIN_y, LOW);
}
// z
if (ledState_z == true) {
time_z = time_z - 1;
digitalWrite (PIN_z, HIGH);
}
if (time_z == 0) {
ledState_z = false;
}
if (ledState_z == false) {
digitalWrite (PIN_z, LOW);
}
delay (1);
}
Python code that generates this mess chap = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'] num = ['2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31','32','33','34','35','36','37','38','39','40','41','42','43','44','45','46','47','48','49','50','51','52','53'] i = 0 k = 0 iteration1 = True while iteration1: print('#define PIN_' + chap[i] + ' ' + num[k]) i = i + 1 k = k + 1 if i > 51: iteration1 = False print() i = 0 iteration2 = True while iteration2: print('#define TIME_' + chap[i] + ' ' + '1000') i = i + 1 if i > 51: iteration2 = False print() i = 0 iteration3 = True while iteration3: print('boolean ledState_' + chap[i] + ' ' + '= false;') i = i + 1 if i > 51: iteration3 = False print() i = 0 iteration4 = True while iteration4: print('int time_' + chap[i] + ' ' + '= 0;') i = i + 1 if i > 51: iteration4 = False i = 0 iteration5 = True while iteration5: print() print('//' + chap[i]) print("if(x == '" + chap[i] + "'){") print(' ledState_' + chap[i] + ' = true;') print(' time_' + chap[i] + ' = TIME_' + chap[i] + ';') print(' x = 0;') print(' }') i = i + 1 if i > 51: iteration5 = False print() print('}') print() i = 0 iteration6 = True while iteration6: print() print('//' + chap[i]) print("if(ledState_" + chap[i] + " == true){") print(' time_' + chap[i] + ' = time_' + chap[i] + ' - 1;') print(' digitalWrite(PIN_' + chap[i] + ', HIGH);') print(' }') print() print("if(time_" + chap[i] + " == 0){") print(' ledState_' + chap[i] + ' = false;') print(' }') print() print("if(ledState_" + chap[i] + " == false){") print(' digitalWrite(PIN_' + chap[i] + ', LOW);') print(' }') i = i + 1 if i > 51: iteration6 = False print() print('delay(1);') print() print('}') print('NEW VERSION') i = 26 iteration7 = True while iteration7: print() print('//' + chap[i]) print("if(x == '" + chap[i] + "'){") print(' digitalWrite (PIN_' + chap[i] + ', !digitalRead(PIN_' + chap[i] + '));') print(' x = 0;') print(' }') i = i + 1 if i > 51: iteration7 = False print() print('}') print()
PS: One of the goals of automation was to avoid human error, which was my surprise when the sketch refused to compile. The reason was that I hurried and wrote the alphabet with one repeating beech.
PPS: The customer was terribly pleased, paid more than agreed, and even allowed to share the code with readers.
Learn Python, gentlemen!