Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
If you get past the previous exercise then you should understand what's going on.
Then, I think your looking at a minimum of building a 3 digit xx.x for setpoint and a 1 digit BCD switch, each with endcaps. Lots of diodes.
No because it now has && in the code & the serial
Somehow you got the inputs and outputs mixed up I believe and your also making little sense. Explain:
Pin 7 is an input and pin #10 is an output.
You had a ground connected to the common of the BCD switch, right? Remove that ground.
Connect the Common to (pin #10), an output of the ULN2003. Pin #10 is labeled O7 for output #7. Pin #7 is the corresponding INPUT.
Putting a high (+5) on pin #7 will put pin #10 to "ground", thus it's now the same as when the common of the BCD switch was grounded. This will read the BCD value or complement depending on the code.
Putting a LOW (ground or OPEN) just opens the common connection and all bits should be a 1. It should read 15 or 0 depending on the code.
You should be able to replace all of these switchNo = switchNo + 1 type expressions with corresponding lines similar to: switchNo = switchNo && 1; etc,
After this if ( val_BCDpin8 == 0) { switchNo = switchNo + 8; } line add
switchNo = !switchNo or this line switchNo = !switchNo; wwhatever works. Not sure if the space is required.
You mentioned to change part of the code to switchNo = switchNo && 1; etc, when I do this the Serial will not read the switchNo but the original code will?
Cheers
/*Willeng
20/9/2014
Modified Sketch
BCD TEST?
*/
const byte BCDpin1 = 2;
const byte BCDpin2 = 3;
const byte BCDpin4 = 4;
const byte BCDpin8 = 5;
void setup()
{ Serial.begin(9600);
pinMode(BCDpin1, INPUT_PULLUP);
pinMode(BCDpin2, INPUT_PULLUP);
pinMode(BCDpin4, INPUT_PULLUP);
pinMode(BCDpin8, INPUT_PULLUP);
}
void loop() {
// read
unsigned int val_BCDpin1 = digitalRead(BCDpin1);
unsigned int val_BCDpin2 = digitalRead(BCDpin2);
unsigned int val_BCDpin4 = digitalRead(BCDpin4);
unsigned int val_BCDpin8 = digitalRead(BCDpin8);
unsigned int switchNo = 0; //reset
if ( val_BCDpin1 == 0) { switchNo = (switchNo | 1); }
if ( val_BCDpin2 == 0) { switchNo = (switchNo | 2); }
if ( val_BCDpin4 == 0) { switchNo = (switchNo | 4); }
if ( val_BCDpin8 == 0) { switchNo = (switchNo | 8); }
{
Serial.print("[BIT8: ");
Serial.print(val_BCDpin8);
Serial.print("] ");
Serial.print("[BIT4: ");
Serial.print(val_BCDpin4);
Serial.print("] ");
Serial.print("[BIT2: ");
Serial.print(val_BCDpin2);
Serial.print("] ");
Serial.print("[BIT1: ");
Serial.print(val_BCDpin1);
Serial.print("] ");
Serial.print("[switchNo: ");
Serial.print(switchNo);
Serial.println("] ");}
delay(3000);
}