Hi there. So for an assignment for Grade 12 Comp. Engineering, my teacher made us solder a bunch of LEDs together to make a 3x3 matrix. Then he told us to create a dice simulation so that whenever you press the push button, the numbers on the dice change to a random one. I'm really new to coding so this is going to be pretty basic but here is my code so far:
int pin [2][3]={ {2, 3, 4}, {8, 9, 10} };
int power [3] = {2, 3, 4};
int ground [3] = {8, 9, 10};
int pushButton= 13;
int randm = 6;
void setup() {
for (int i=2;i<11;i++){
pinMode (i,OUTPUT);
}
pinMode(pushButton, INPUT);
}
void loop() {
off ();
if (randm = 1) {
one();
}
else if (randm == 2) {
two();
}
else if(randm == 2) {
three();
}
else if(randm == 4) {
four();
}
else if(randm == 5) {
five ();
}
else if(randm == 6) {
six ();
}
if (digitalRead(13) == HIGH) {
randm = random (1, 6);
}
Serial.print(2);
}
void one () {
digitalWrite (power [1], HIGH);
digitalWrite (ground [1], LOW);
delay(100);
}
void two (){
digitalWrite (power[0],HIGH);
digitalWrite (ground[2],LOW);
delay(100);
off();
digitalWrite (power[2],HIGH);
digitalWrite (ground[0],LOW);
delay(100);
}
void three (){
two();
off();
one();
off(); //take off if doesn't work.
}
void four(){
digitalWrite (power[0],HIGH);
digitalWrite (ground[0],LOW);
digitalWrite (power[2],HIGH);
digitalWrite (ground[2],LOW);
delay(100);
}
void five(){
one();
delay(100);
off();
four ();
}
void six(){
digitalWrite (power[0],HIGH);
digitalWrite (power[2],HIGH);
digitalWrite (ground[0],LOW);
digitalWrite (ground[1],LOW);
digitalWrite (ground[2],LOW);
delay(100);
}
void off (){
for (int j=0;j<3;j++){
digitalWrite (power[j],LOW);
}
for (int i=0;i<3;i++){
digitalWrite (ground[i],HIGH);
}
}
I checked to see if it worked with the hardware this morning but it didn't. If you see anything wrong or missing in this code, please point it out. Thank you.