Sorry for being a complete Noob, but I've got a little project that I'm trying to build, unfortunately its been 20 years since I've done any coding, so I'm a little rusty.
Long story short, I work for an elevator company and I'm trying to make a Binary floor indicator simulator for a long term test unit.
I've looked at a few of the Binary codes and they all work on my UNO, but here's the thing, I need it to count up and down, here's the breakdown of what I'm trying to simulate.
Digital pins 0-7
Binary count on pins 0-4
Binary count up from 00001 to 11111 then count down to 00001
While the binary count is going up turn pin 5 HIGH, pin 6 LOW (simulates the up arrow)
While the binary count is going down turn pin 5 LOW, pin 6 HIGH (simulates the down arrow)
Lastly it would be fun to simulate a random door open signal on pin 7 going HIGH, but when this is active the binary count needs to pause for 10 seconds while pin 7 is HIGH (this isn't completely needed but would be fun)
Currently this is the code that I'm working with, got it from another old thread.
int ledPins[8] = {0, 1, 2, 3, 4, 5, 6, 7};
const int numberofleds = 5;
/* pins start at zero
sorry, I didn't bother checking if this array was necessary or if I could use pin output states in an "if" statement
*/
int pinstates[8] = {0, 0, 0, 0, 0, 0, 0, 0};
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pins as outputs.
for (int i = 0; i < numberofleds + 3; i++)
pinMode(ledPins*, OUTPUT);*
}
// the loop function runs over and over again forever
void loop() {
- delay(2000);*
- fliploop(leastsignificantones());*
}
int leastsignificantones() { - int i = 0;*
_ while (pinstates == 1 && i <= numberofleds - 2) {_
* i = i + 1;*
* }*
* return i ;*
}
//starting from least significant bits
void fliploop(int numberofbitstoflip) {
* for (int i = 0; i <= numberofbitstoflip; i++)*
* flipbit(i);*
}
void flipbit(int i) {
* digitalWrite(5, HIGH);*
* digitalWrite(6, LOW);*
_ if (pinstates == 0) {
digitalWrite(ledPins*, HIGH);
pinstates = 1;
}
else {
digitalWrite(ledPins, LOW);
pinstates = 0;
}
}*_