Skip to main content
Became Hot Network Question
Code formatting.
Source Link
Edgar Bonet
  • 45.2k
  • 4
  • 42
  • 81

#define ROW_1 3
#define ROW_2 4
#define ROW_3 5
#define ROW_4 6
#define ROW_5 7

#define COL_1 8 #define COL_2 9
#define COL_3 10
#define COL_4 11
#define COL_5 12
#define COL_6 13

const byte rows[] = { ROW_1, ROW_2, ROW_3, ROW_4, ROW_5 };

byte Zero[] = {B011110,B010010,B010010,B010010,B011110}; byte One[] = {B001100,B000100,B000100,B000100,B000100}; byte Two[] = {B011110,B000010,B011110,B010000,B011110}; byte Three[] = {B011110,B000010,B001110,B000010,B011110}; byte Four[] = {B010010,B010010,B011110,B000010,B000010}; byte Five[] = {B011110,B010000,B011110,B000010,B011110}; byte Six[] = {B011110,B010000,B011110,B010010,B011110}; byte Seven[] = {B011100,B000100,B000100,B000100,B000100}; byte Eight[] = {B011110,B010010,B011110,B010010,B011110}; byte Nine[] = {B011110,B010010,B011110,B000010,B011110};

void setColumns(byte b) { digitalWrite(COL_1, (~b >> 0) & 0x01); digitalWrite(COL_2, (~b >> 1) & 0x01); digitalWrite(COL_3, (~b >> 2) & 0x01); digitalWrite(COL_4, (~b >> 3) & 0x01); digitalWrite(COL_5, (~b >> 4) & 0x01); digitalWrite(COL_6, (~b >> 5) & 0x01);

}

void drawScreen(byte buffer2[]){

for (byte i = 0; i < 5; i++) {
setColumns(buffer2[i]); 
      
digitalWrite(rows[i], HIGH);
digitalWrite(rows[i], LOW);
    
}

}

void setup() { Serial.begin(9600); for (byte i = 2; i <= 13; i++) pinMode(i, OUTPUT);

}

void loop() { int digit; if(Serial.available()) {

digit = Serial.read(); Serial.println(digit);

}

switch (digit) {
  
case 48:
drawScreen(Zero);    
break;
  
case 49:
drawScreen(One);    
break;
  
case 50:
drawScreen(Two);          
break;
  
case 51:
drawScreen(Three);    
break;
  
case 52:
drawScreen(Four);   
break;
  
case 53:
drawScreen(Five);    
break;
  
case 54:
drawScreen(Six);
break;
  
case 55:
drawScreen(Seven);   
break;
  
case 56:
drawScreen(Eight); 
break; 
  
case 57:
drawScreen(Nine);  
break;

}

}

#define ROW_1 3
#define ROW_2 4
#define ROW_3 5
#define ROW_4 6
#define ROW_5 7

#define COL_1 8
#define COL_2 9
#define COL_3 10
#define COL_4 11
#define COL_5 12
#define COL_6 13

const byte rows[] = {
    ROW_1, ROW_2, ROW_3, ROW_4, ROW_5
};

byte Zero[]  = {B011110, B010010, B010010, B010010, B011110};
byte One[]   = {B001100, B000100, B000100, B000100, B000100};
byte Two[]   = {B011110, B000010, B011110, B010000, B011110};
byte Three[] = {B011110, B000010, B001110, B000010, B011110};
byte Four[]  = {B010010, B010010, B011110, B000010, B000010};
byte Five[]  = {B011110, B010000, B011110, B000010, B011110};
byte Six[]   = {B011110, B010000, B011110, B010010, B011110};
byte Seven[] = {B011100, B000100, B000100, B000100, B000100};
byte Eight[] = {B011110, B010010, B011110, B010010, B011110};
byte Nine[]  = {B011110, B010010, B011110, B000010, B011110};

void setColumns(byte b) {
    digitalWrite(COL_1, (~b >> 0) & 0x01);
    digitalWrite(COL_2, (~b >> 1) & 0x01);
    digitalWrite(COL_3, (~b >> 2) & 0x01);
    digitalWrite(COL_4, (~b >> 3) & 0x01);
    digitalWrite(COL_5, (~b >> 4) & 0x01);
    digitalWrite(COL_6, (~b >> 5) & 0x01);
}

void  drawScreen(byte buffer2[]){
    for (byte i = 0; i < 5; i++) {
        setColumns(buffer2[i]);
        digitalWrite(rows[i], HIGH);
        digitalWrite(rows[i], LOW);
    }
}

void setup() {
    Serial.begin(9600);
    for (byte i = 2; i <= 13; i++)
        pinMode(i, OUTPUT);
}

void loop()
{
    int digit;
    if(Serial.available()) {
        digit = Serial.read();
        Serial.println(digit);
    }
    switch (digit) {
        case 48:
            drawScreen(Zero);
            break;
        case 49:
            drawScreen(One);
            break;
        case 50:
            drawScreen(Two);
            break;
        case 51:
            drawScreen(Three);
            break;
        case 52:
            drawScreen(Four);
            break;
        case 53:
            drawScreen(Five);
            break;
        case 54:
            drawScreen(Six);
            break;
        case 55:
            drawScreen(Seven);
            break;
        case 56:
            drawScreen(Eight);
            break;
        case 57:
            drawScreen(Nine);
            break;
    }
}

#define ROW_1 3
#define ROW_2 4
#define ROW_3 5
#define ROW_4 6
#define ROW_5 7

#define COL_1 8 #define COL_2 9
#define COL_3 10
#define COL_4 11
#define COL_5 12
#define COL_6 13

const byte rows[] = { ROW_1, ROW_2, ROW_3, ROW_4, ROW_5 };

byte Zero[] = {B011110,B010010,B010010,B010010,B011110}; byte One[] = {B001100,B000100,B000100,B000100,B000100}; byte Two[] = {B011110,B000010,B011110,B010000,B011110}; byte Three[] = {B011110,B000010,B001110,B000010,B011110}; byte Four[] = {B010010,B010010,B011110,B000010,B000010}; byte Five[] = {B011110,B010000,B011110,B000010,B011110}; byte Six[] = {B011110,B010000,B011110,B010010,B011110}; byte Seven[] = {B011100,B000100,B000100,B000100,B000100}; byte Eight[] = {B011110,B010010,B011110,B010010,B011110}; byte Nine[] = {B011110,B010010,B011110,B000010,B011110};

void setColumns(byte b) { digitalWrite(COL_1, (~b >> 0) & 0x01); digitalWrite(COL_2, (~b >> 1) & 0x01); digitalWrite(COL_3, (~b >> 2) & 0x01); digitalWrite(COL_4, (~b >> 3) & 0x01); digitalWrite(COL_5, (~b >> 4) & 0x01); digitalWrite(COL_6, (~b >> 5) & 0x01);

}

void drawScreen(byte buffer2[]){

for (byte i = 0; i < 5; i++) {
setColumns(buffer2[i]); 
      
digitalWrite(rows[i], HIGH);
digitalWrite(rows[i], LOW);
    
}

}

void setup() { Serial.begin(9600); for (byte i = 2; i <= 13; i++) pinMode(i, OUTPUT);

}

void loop() { int digit; if(Serial.available()) {

digit = Serial.read(); Serial.println(digit);

}

switch (digit) {
  
case 48:
drawScreen(Zero);    
break;
  
case 49:
drawScreen(One);    
break;
  
case 50:
drawScreen(Two);          
break;
  
case 51:
drawScreen(Three);    
break;
  
case 52:
drawScreen(Four);   
break;
  
case 53:
drawScreen(Five);    
break;
  
case 54:
drawScreen(Six);
break;
  
case 55:
drawScreen(Seven);   
break;
  
case 56:
drawScreen(Eight); 
break; 
  
case 57:
drawScreen(Nine);  
break;

}

}

#define ROW_1 3
#define ROW_2 4
#define ROW_3 5
#define ROW_4 6
#define ROW_5 7

#define COL_1 8
#define COL_2 9
#define COL_3 10
#define COL_4 11
#define COL_5 12
#define COL_6 13

const byte rows[] = {
    ROW_1, ROW_2, ROW_3, ROW_4, ROW_5
};

byte Zero[]  = {B011110, B010010, B010010, B010010, B011110};
byte One[]   = {B001100, B000100, B000100, B000100, B000100};
byte Two[]   = {B011110, B000010, B011110, B010000, B011110};
byte Three[] = {B011110, B000010, B001110, B000010, B011110};
byte Four[]  = {B010010, B010010, B011110, B000010, B000010};
byte Five[]  = {B011110, B010000, B011110, B000010, B011110};
byte Six[]   = {B011110, B010000, B011110, B010010, B011110};
byte Seven[] = {B011100, B000100, B000100, B000100, B000100};
byte Eight[] = {B011110, B010010, B011110, B010010, B011110};
byte Nine[]  = {B011110, B010010, B011110, B000010, B011110};

void setColumns(byte b) {
    digitalWrite(COL_1, (~b >> 0) & 0x01);
    digitalWrite(COL_2, (~b >> 1) & 0x01);
    digitalWrite(COL_3, (~b >> 2) & 0x01);
    digitalWrite(COL_4, (~b >> 3) & 0x01);
    digitalWrite(COL_5, (~b >> 4) & 0x01);
    digitalWrite(COL_6, (~b >> 5) & 0x01);
}

void  drawScreen(byte buffer2[]){
    for (byte i = 0; i < 5; i++) {
        setColumns(buffer2[i]);
        digitalWrite(rows[i], HIGH);
        digitalWrite(rows[i], LOW);
    }
}

void setup() {
    Serial.begin(9600);
    for (byte i = 2; i <= 13; i++)
        pinMode(i, OUTPUT);
}

void loop()
{
    int digit;
    if(Serial.available()) {
        digit = Serial.read();
        Serial.println(digit);
    }
    switch (digit) {
        case 48:
            drawScreen(Zero);
            break;
        case 49:
            drawScreen(One);
            break;
        case 50:
            drawScreen(Two);
            break;
        case 51:
            drawScreen(Three);
            break;
        case 52:
            drawScreen(Four);
            break;
        case 53:
            drawScreen(Five);
            break;
        case 54:
            drawScreen(Six);
            break;
        case 55:
            drawScreen(Seven);
            break;
        case 56:
            drawScreen(Eight);
            break;
        case 57:
            drawScreen(Nine);
            break;
    }
}
added 2218 characters in body
Source Link

enter image description here So I'm a beginner at Arduino and I have to light up an LED grid to show digits from 0-9. I wrote a bit of code (with the help of some people) and it's like 90% done but there's this ONE problem. I used a switch case to light up the LEDs (so if the user writes a 5 then the switch case will make the LEDs show the digit 5) but it only showedshows up for like a SPLIT second. So I put a while-loop in the switch cases to keep the LEDs lit up but now they can't go out anymore. I need the LEDs to stay lit and show the chosen digit until the user inputs a NEW digit in the serial plotter so then the LEDs stop showing the first digit but the new chosen digit and so forth. Here's a link to Tinkercad with my setup and code. And yes I'm aware that there's an issue with the code which makes the serial plotter take a '0' as '48'Any fixes for this?

#define ROW_1 3
#define ROW_2 4
#define ROW_3 5
#define ROW_4 6
#define ROW_5 7

#define COL_1 8 #define COL_2 9
#define COL_3 10
#define COL_4 11
#define COL_5 12
#define COL_6 13

const byte rows[] = { ROW_1, '1' as '49'ROW_2, '2' as '50'ROW_3, and so forthROW_4, ROW_5 };

byte Zero[] = {B011110,B010010,B010010,B010010,B011110}; byte One[] = {B001100,B000100,B000100,B000100,B000100}; byte Two[] = {B011110,B000010,B011110,B010000,B011110}; byte Three[] = {B011110,B000010,B001110,B000010,B011110}; byte Four[] = {B010010,B010010,B011110,B000010,B000010}; byte Five[] = {B011110,B010000,B011110,B000010,B011110}; byte Six[] = {B011110,B010000,B011110,B010010,B011110}; byte Seven[] = {B011100,B000100,B000100,B000100,B000100}; byte Eight[] = {B011110,B010010,B011110,B010010,B011110}; byte Nine[] = {B011110,B010010,B011110,B000010,B011110};

void setColumns(byte b) { digitalWrite(COL_1, (~b >> 0) & 0x01); digitalWrite(COL_2, (~b >> 1) & 0x01); digitalWrite(COL_3, (~b >> 2) & 0x01); digitalWrite(COL_4, (~b >> 3) & 0x01); digitalWrite(COL_5, (~b >> 4) & 0x01); digitalWrite(COL_6, (~b >> 5) & 0x01);

}

void drawScreen(byte buffer2[]){

for (byte i = 0; i < 5; i++) {
setColumns(buffer2[i]); 
      
digitalWrite(rows[i], HIGH);
digitalWrite(rows[i], LOW);
    
}

}

void setup() { Serial. This isn't THAT big of a deal but if someone could fix that as well then I would be even more grateful!begin(9600); for (byte i = 2; i <= 13; i++) pinMode(i, OUTPUT);

https://www.tinkercad.com/things/6AoINgjBqFr-led-matrix/editel}

void loop() { int digit; if(Serial.available()) {

digit = Serial.read(); Serial.println(digit);

}

switch (digit) {
  
case 48:
drawScreen(Zero);    
break;
  
case 49:
drawScreen(One);    
break;
  
case 50:
drawScreen(Two);          
break;
  
case 51:
drawScreen(Three);    
break;
  
case 52:
drawScreen(Four);   
break;
  
case 53:
drawScreen(Five);    
break;
  
case 54:
drawScreen(Six);
break;
  
case 55:
drawScreen(Seven);   
break;
  
case 56:
drawScreen(Eight); 
break; 
  
case 57:
drawScreen(Nine);  
break;

}

}

enter image description here So I'm a beginner at Arduino and I have to light up an LED grid to show digits from 0-9. I wrote a bit of code (with the help of some people) and it's like 90% done but there's this ONE problem. I used a switch case to light up the LEDs (so if the user writes a 5 then the switch case will make the LEDs show the digit 5) but it only showed up for like a SPLIT second. So I put a while-loop in the switch cases to keep the LEDs lit up but now they can't go out anymore. I need the LEDs to stay lit and show the chosen digit until the user inputs a NEW digit in the serial plotter so then the LEDs stop showing the first digit but the new chosen digit and so forth. Here's a link to Tinkercad with my setup and code. And yes I'm aware that there's an issue with the code which makes the serial plotter take a '0' as '48', '1' as '49', '2' as '50', and so forth. This isn't THAT big of a deal but if someone could fix that as well then I would be even more grateful!

https://www.tinkercad.com/things/6AoINgjBqFr-led-matrix/editel

enter image description here So I'm a beginner at Arduino and I have to light up an LED grid to show digits from 0-9. I wrote a bit of code (with the help of some people) and it's like 90% done but there's this ONE problem. I used a switch case to light up the LEDs (so if the user writes a 5 then the switch case will make the LEDs show the digit 5) but it only shows up for like a SPLIT second.Any fixes for this?

#define ROW_1 3
#define ROW_2 4
#define ROW_3 5
#define ROW_4 6
#define ROW_5 7

#define COL_1 8 #define COL_2 9
#define COL_3 10
#define COL_4 11
#define COL_5 12
#define COL_6 13

const byte rows[] = { ROW_1, ROW_2, ROW_3, ROW_4, ROW_5 };

byte Zero[] = {B011110,B010010,B010010,B010010,B011110}; byte One[] = {B001100,B000100,B000100,B000100,B000100}; byte Two[] = {B011110,B000010,B011110,B010000,B011110}; byte Three[] = {B011110,B000010,B001110,B000010,B011110}; byte Four[] = {B010010,B010010,B011110,B000010,B000010}; byte Five[] = {B011110,B010000,B011110,B000010,B011110}; byte Six[] = {B011110,B010000,B011110,B010010,B011110}; byte Seven[] = {B011100,B000100,B000100,B000100,B000100}; byte Eight[] = {B011110,B010010,B011110,B010010,B011110}; byte Nine[] = {B011110,B010010,B011110,B000010,B011110};

void setColumns(byte b) { digitalWrite(COL_1, (~b >> 0) & 0x01); digitalWrite(COL_2, (~b >> 1) & 0x01); digitalWrite(COL_3, (~b >> 2) & 0x01); digitalWrite(COL_4, (~b >> 3) & 0x01); digitalWrite(COL_5, (~b >> 4) & 0x01); digitalWrite(COL_6, (~b >> 5) & 0x01);

}

void drawScreen(byte buffer2[]){

for (byte i = 0; i < 5; i++) {
setColumns(buffer2[i]); 
      
digitalWrite(rows[i], HIGH);
digitalWrite(rows[i], LOW);
    
}

}

void setup() { Serial.begin(9600); for (byte i = 2; i <= 13; i++) pinMode(i, OUTPUT);

}

void loop() { int digit; if(Serial.available()) {

digit = Serial.read(); Serial.println(digit);

}

switch (digit) {
  
case 48:
drawScreen(Zero);    
break;
  
case 49:
drawScreen(One);    
break;
  
case 50:
drawScreen(Two);          
break;
  
case 51:
drawScreen(Three);    
break;
  
case 52:
drawScreen(Four);   
break;
  
case 53:
drawScreen(Five);    
break;
  
case 54:
drawScreen(Six);
break;
  
case 55:
drawScreen(Seven);   
break;
  
case 56:
drawScreen(Eight); 
break; 
  
case 57:
drawScreen(Nine);  
break;

}

}

added 85 characters in body
Source Link

Soenter image description here So I'm a beginner at Arduino and I have to light up an LED grid to show digits from 0-9. I wrote a bit of code (with the help of some people) and it's like 90% done but there's this ONE problem. I used a switch case to light up the LEDs (so if the user writes a 5 then the switch case will make the LEDs show the digit 5) but it only showed up for like a SPLIT second. So I put a while-loop in the switch cases to keep the LEDs lit up but now they can't go out anymore. I need the LEDs to stay lit and show the chosen digit until the user inputs a NEW digit in the serial plotter so then the LEDs stop showing the first digit but the new chosen digit and so forth. Here's a link to Tinkercad with my setup and code. And yes I'm aware that there's an issue with the code which makes the serial plotter take a '0' as '48', '1' as '49', '2' as '50', and so forth. This isn't THAT big of a deal but if someone could fix that as well then I would be even more grateful!

https://www.tinkercad.com/things/6AoINgjBqFr-led-matrix/editel

So I'm a beginner at Arduino and I have to light up an LED grid to show digits from 0-9. I wrote a bit of code (with the help of some people) and it's like 90% done but there's this ONE problem. I used a switch case to light up the LEDs (so if the user writes a 5 then the switch case will make the LEDs show the digit 5) but it only showed up for like a SPLIT second. So I put a while-loop in the switch cases to keep the LEDs lit up but now they can't go out anymore. I need the LEDs to stay lit and show the chosen digit until the user inputs a NEW digit in the serial plotter so then the LEDs stop showing the first digit but the new chosen digit and so forth. Here's a link to Tinkercad with my setup and code. And yes I'm aware that there's an issue with the code which makes the serial plotter take a '0' as '48', '1' as '49', '2' as '50', and so forth. This isn't THAT big of a deal but if someone could fix that as well then I would be even more grateful!

https://www.tinkercad.com/things/6AoINgjBqFr-led-matrix/editel

enter image description here So I'm a beginner at Arduino and I have to light up an LED grid to show digits from 0-9. I wrote a bit of code (with the help of some people) and it's like 90% done but there's this ONE problem. I used a switch case to light up the LEDs (so if the user writes a 5 then the switch case will make the LEDs show the digit 5) but it only showed up for like a SPLIT second. So I put a while-loop in the switch cases to keep the LEDs lit up but now they can't go out anymore. I need the LEDs to stay lit and show the chosen digit until the user inputs a NEW digit in the serial plotter so then the LEDs stop showing the first digit but the new chosen digit and so forth. Here's a link to Tinkercad with my setup and code. And yes I'm aware that there's an issue with the code which makes the serial plotter take a '0' as '48', '1' as '49', '2' as '50', and so forth. This isn't THAT big of a deal but if someone could fix that as well then I would be even more grateful!

https://www.tinkercad.com/things/6AoINgjBqFr-led-matrix/editel

Source Link
Loading