- Reaction score
- 4,348
I counted 7 one millisecond delays, one after the other in this sub-routine. I suppose for now that from the start to end of this sub-routine takes of the order 7mS. I cannot quickly work out if 7mS is to generate a single column of 7 LEDs, a single line of 5 LEDs or all 35 LEDs. Please check my analysis because I am pretty sure I have not completely understood your code. You understand how you have written the code so ought to be able to arrive at figure of about 30Hz or lower which you mentioned earlier.Exactly.
Here is the actual program for 'letter A' that I made and presented in the movie.
You may not understand everything but read the entire program anyway and you will get something out of it. I've also put notes what is line and what is column.
(it was imperative to switch to Input everything after each step, with my custom Reset(); method, otherwise it was liting up the entire next line or column)
Remember a line is HIGH because is +5V and a column is LOW because is 0V. So we lit a single line putting +5V on line01(for ex) and 0v on each desired column.
Code:#include "Arduino.h" //core library that contains all of the Arduino’s built-in functions (from 2022) #include <Adafruit_MCP23X17.h> //this is Adafruit-MCP23017-Arduino-Library version 2.1.0 Adafruit_MCP23X17 mcp1; //Instantiate mcp1 object void setup() { Serial.begin(19200); mcp1.begin_I2C(0x20); for(int i = 0; i <= 15; i++) { mcp1.pinMode(i, INPUT); } for(int i = 0; i <=15; i++) { mcp1.digitalWrite(i, LOW); } //LED MATRIX DISPLAY - Single LED - one by one /* LOGIC: //Columns---------------------------------------- // mcp1.digitalWrite(1, LOW); //A1=1=column A // mcp1.digitalWrite(10, LOW);//B1=10=column B // mcp1.digitalWrite(3, LOW); //A3=3=column C middle // mcp1.digitalWrite(11, LOW);//B2=11=column C middle // mcp1.digitalWrite(4, LOW); //A4=4=column D // mcp1.digitalWrite(13, LOW);//B6=13=column E //Lines---------------------------------------- // mcp1.digitalWrite(5, HIGH);//Line1 // mcp1.digitalWrite(0, HIGH);//Line2 // mcp1.digitalWrite(6, HIGH);//Line3 // mcp1.digitalWrite(2, HIGH);//Line4 // mcp1.digitalWrite(12, HIGH);//Line4 // mcp1.digitalWrite(8, HIGH);//Line5 // mcp1.digitalWrite(14, HIGH);//Line6 // mcp1.digitalWrite(9, HIGH);//Line7 */ } void Reset() { for(int i = 0; i <=15; i++) { mcp1.pinMode(i, INPUT); mcp1.digitalWrite(i, LOW); } } int dly = 1; void chr_A() { //line1 mcp1.pinMode(5, OUTPUT); //line mcp1.digitalWrite(5, HIGH); mcp1.pinMode(10, OUTPUT); //column mcp1.digitalWrite(10, LOW); mcp1.pinMode(3, OUTPUT); //column mcp1.digitalWrite(3, LOW); mcp1.pinMode(4, OUTPUT); //column mcp1.digitalWrite(4, LOW); delay(dly); Reset(); //line2 mcp1.pinMode(0, OUTPUT); //line mcp1.digitalWrite(0, HIGH); mcp1.pinMode(1, OUTPUT); //column mcp1.digitalWrite(1, LOW); mcp1.pinMode(13, OUTPUT); //column mcp1.digitalWrite(13, LOW); delay(dly); Reset(); //line3 mcp1.pinMode(6, OUTPUT); //line mcp1.digitalWrite(6, HIGH); mcp1.pinMode(1, OUTPUT); //column mcp1.digitalWrite(1, LOW); mcp1.pinMode(13, OUTPUT); //column mcp1.digitalWrite(13, LOW); delay(dly); Reset(); //line4-midle mcp1.pinMode(2, OUTPUT); //line mcp1.digitalWrite(2, HIGH); mcp1.pinMode(1, OUTPUT); //column mcp1.digitalWrite(1, LOW); mcp1.pinMode(10, OUTPUT); //column mcp1.digitalWrite(10, LOW); mcp1.pinMode(3, OUTPUT); //column mcp1.digitalWrite(3, LOW); mcp1.pinMode(4, OUTPUT); //column mcp1.digitalWrite(4, LOW); mcp1.pinMode(13, OUTPUT); //column mcp1.digitalWrite(13, LOW); delay(dly); Reset(); //line5 mcp1.pinMode(8, OUTPUT); //line mcp1.digitalWrite(8, HIGH); mcp1.pinMode(1, OUTPUT); //column mcp1.digitalWrite(1, LOW); mcp1.pinMode(13, OUTPUT); //column mcp1.digitalWrite(13, LOW); delay(dly); Reset(); //line6 mcp1.pinMode(14, OUTPUT); //line mcp1.digitalWrite(14, HIGH); mcp1.pinMode(1, OUTPUT); //column mcp1.digitalWrite(1, LOW); mcp1.pinMode(13, OUTPUT); //column mcp1.digitalWrite(13, LOW); delay(dly); Reset(); //line7 mcp1.pinMode(9, OUTPUT); //line mcp1.digitalWrite(9, HIGH); mcp1.pinMode(1, OUTPUT); //column mcp1.digitalWrite(1, LOW); mcp1.pinMode(13, OUTPUT); //column mcp1.digitalWrite(13, LOW); delay(dly); Reset(); } void loop() { chr_A(); }
If 7mS is for all 35 LEDs then the refresh rate is 1/0.007 = 140Hz.
If 7mS is for a column of 7 LEDs, and there are 5 columns the refresh rate is 140/5 = 28Hz.
If 7mS is for a line of 5 LEDs and their are 7 lines the refresh rate is 140/7 = 20Hz
Why do have delay command at all in this sub routine?
Last edited: