The below short peice of code shows me desperately trying to make number 7 display, newboy here. Could anyone point out the fault?
int RLED = 5;
int GLED = 2 ;
int MYARRAY[]={0,0,0,0,1,1,0,1};
void setup() {
Serial.begin(9600);
pinMode(13,OUTPUT);
Many issues here:
All outputs should be set to output before digitalwrite
Counter will always be zero.
The ; shouldn't be present here );{
The array is initialized as one dimensional and applied as two dimensional. This may be ok, but I doubt whether you are aware.
Could you add a wiring scheme?
To me it is not at all clear what you are trying to accomplish...
//Using arrrays, for loop, and digital write to make a
//7-LED display from 9-0,with a red LED on, and 5-0
//afterwards, with a green LED shimmering
int RLED = 5;
int GLED = 2 ;
byte GLEDValue = 0;
/* a
f b
g
e c
d
*/
int SevenSegPins[7] = {3, 4, 6, 7, 8, 9, 10};
int Numbers[10][7] = {
//a b c d e f g
{0,0,0,0,0,0,1}, //0
{1,0,0,1,1,1,1}, //1
{0,0,1,0,0,1,0}, //2
{0,0,0,0,1,1,0}, //3
{1,0,0,1,1,0,0}, //4
{0,1,0,0,1,0,0}, //5
{0,1,0,0,0,0,0}, //6
{0,0,0,1,1,1,1}, //7
{0,0,0,0,0,0,0}, //8
{0,0,0,0,1,0,0} //9
};
void setup() {
Serial.begin(9600);
pinMode(RLED,OUTPUT);
pinMode(GLED,OUTPUT);
for (int sevSeg=0; sevSeg < 7; sevSeg++){
pinMode(SevenSegPins[sevSeg],OUTPUT);
}
}
void loop() {
digitalWrite(RLED,1);
byte GLEDValue = 0;
digitalWrite(GLED,GLEDValue);
for(int counter=9;counter>=0;counter--){
for (int sevSeg=0; sevSeg < 7; sevSeg++){
digitalWrite(SevenSegPins[sevSeg],Numbers[counter][sevSeg]);
}
delay(1000);
}
digitalWrite(RLED,0);
for(int counter=5;counter>=0;counter--){
for (int sevSeg=0; sevSeg < 7; sevSeg++){
digitalWrite(SevenSegPins[sevSeg],Numbers[counter][sevSeg]);
}
for (int blinktimes = 0; blinktimes < 10; blinktimes++){
GLEDValue = !GLEDValue;
digitalWrite(GLED,GLEDValue);
delay(100);
}
}
}
Thanks for the super straightforward code man. Quite confused by the large amounts of variables tho, esp for the last bit, you didn't seem to use blinktimes at all? I also don't get GLEDValue =!GLEDValue, why does 0 not = 0 run?