Since I found a seven-segment display in the kit I checked out from the library, I figured I would give it a shot! Step one of course was to get everything on Tinkercard, and once I just copied over from what I found on a few online resources, everything worked perfectly!
Ah, what a lovely day -- I'm going to get things done early....
Nope.
Wired everything the same as Tinkercad. Pressed button. Nothing.
Rewrote code so not dependent on the button. Nothing.
Checked security of all the wires. Nothing.
Pulled out all the wires and put them back together. Still nothing.
Time for bed, defeated and ashamed.
The next day, clearly I must've just done it wrong.
Pulled out all the wires and put them back together. Still nothing. This is getting old.
I started looking online for all the ways to test the display itself -- clearly the part must be broken. Unfortunately all the troubleshooting tips required using a multimeter, which I don't have. But while looking at everything, I realized there are two types of 7-segment displays: Anode and Cathode. I moved the one resistor wire from the + to the - side and .... magic! Didn't get anything that looked like numbers on the display, but it at least started lighting up.
I did some more looking around online, and went back to Tinkercad. This video I actually talk through it, so if you normally have sound off, having the sound on might help.
And here we get the circuit diagram!
All kinds of fun, but it's working now!
And here's the code! Right now it's just doing the numbers 1 through six, but it could be edited to also do 0 and 7 - 9.
unsignedconstint A = 13;
unsignedconstint B = 12;
unsignedconstint C = 11;
unsignedconstint D = 10;
unsignedconstint E = 9;
unsignedconstint F = 8;
unsignedconstint G = 7;
unsignedconstint H = 6;
int randomNumber;
int buttonPin = 2;
int buttonState = 0;
voidsetup(){
int index;
pinMode(A, OUTPUT);
pinMode(B, OUTPUT);
pinMode(C, OUTPUT);
pinMode(D, OUTPUT);
pinMode(E, OUTPUT);
pinMode(F, OUTPUT);
pinMode(G, OUTPUT);
pinMode(H, OUTPUT);
pinMode(buttonPin, INPUT);
Serial.begin(9600);
randomSeed(analogRead(0));
delay(100);
} // end setup
voidloop(){
int index;
buttonState = digitalRead(buttonPin);
if(buttonState == HIGH){
delay(100);
randomNumber = random(1,7); // Generate a random # from 1 to 6
No comments:
Post a Comment