what else posted needs corrected???
the display isn’t a priority in terms of brightness on the project. its more that I count the sensors up and display them somehow on the 7 segment.
my updated code now, on the serial monitor is recognising the state of the 4 different sensors, and it also counting up the states to a total. My struggle is getting that total sent onto the 7 segment.
my new updated code is
byte numbers[10] = {
B11111100, B01100000, B11011010, B11110010, B01100110,
B10110110, B10111110, B11100000, B11111110, B11100110
};
void setup() {
for(int i = 2; i <= 8; i++) {
pinMode(i, OUTPUT);
}
pinMode(9, INPUT);
pinMode(10, INPUT);
pinMode(11, INPUT);
pinMode(12, INPUT);
Serial.begin(1200);
}
int counter = 0;
bool go_by_switch = true;
int last_input_value = LOW;
void loop() {
int count;
/* if(go_by_switch) {
int switch_input_value = digitalRead(9);
if(last_input_value == LOW && switch_input_value == HIGH) {
counter = (counter + 1) % 10;
}
last_input_value = switch_input_value;
} else {
delay(500);
counter = (counter + 1) % 10;
} */
bottle_counter ();
delay(4000);
writeNumber(counter);
}
void writeNumber(int number) {
if(number < 0 || number > 9) {
return;
}
byte mask = numbers[number];
byte currentPinMask = B10000000;
for(int i = 2; i <= 8; i++) { if(mask & currentPinMask) digitalWrite(i,HIGH); else digitalWrite(i,LOW); currentPinMask = currentPinMask >> 1;
}
}
void bottle_counter () {
int count=0;
int bottle_onoff1;
int bottle_onoff2;
int bottle_onoff3;
int bottle_onoff4;
{
bottle_onoff1=digitalRead(9);
bottle_onoff2=digitalRead(10);
bottle_onoff3=digitalRead(11);
bottle_onoff4=digitalRead(12);
if (bottle_onoff1==HIGH)
{
count=count+1;
Serial.print("sensor 1 = ");
Serial.print(bottle_onoff1);
Serial.println();
}
else {
Serial.print("sensor 1 = ");
Serial.print (bottle_onoff1);
Serial.println();
}
if (bottle_onoff2==HIGH)
{
count=count+1;
Serial.print("sensor 2 = ");
Serial.print(bottle_onoff2);
Serial.println();
}
else {
Serial.print("sensor 2 = ");
Serial.print (bottle_onoff2);
Serial.println();
}
if (bottle_onoff3==HIGH)
{
count=count+1;
Serial.print("sensor 3 = ");
Serial.print(bottle_onoff3);
Serial.println();
}
else {
Serial.print("sensor 3 = ");
Serial.print (bottle_onoff3);
Serial.println();
}
if (bottle_onoff4==HIGH)
{
count=count+1;
Serial.print("sensor 4 = ");
Serial.print(bottle_onoff4);
Serial.println();
}
else {
Serial.print("sensor 4 = ");
Serial.print (bottle_onoff4);
Serial.println();
}
}
Serial.print (count);
}
my serial monitor I have attached is showing the states and the total at bottom. obviously it is with no sensors pressed