I am working on a project that lights up a numeric diplay.May question is.i want the the display
to write 3 when the sensor trigger pin number 10 but i want the to write 2 when pin 10 and 11
will trigger.What i have to write in the code?
if (pin 10 is triggered and pin 11 is triggered}
{
write 2 to the display
}
else if (pin 10 is triggered)
{
write 3 to the display
}
// Define the LED digit patterns
// Note that these patterns are for common anode displays
// For common cathode displays, change the 1's to 0's and 0's to 1's
// 1 = LED on, 0 = LED off, in this order:
// Arduino pin: 2,3,4,5,6,7,8,9
byte seven_seg_digits[14][7] = { { 0,0,0,0,0,0,1 }, // = 0
{ 1,0,0,1,1,1,1 }, // = 1
{ 0,0,1,0,0,1,0 }, // = 2
{ 0,0,0,0,1,1,0 }, // = 3
{ 1,0,0,1,1,0,0 }, // = 4
{ 0,1,0,0,1,0,0 }, // = 5
{ 0,1,0,0,0,0,0 }, // = 6
{ 0,0,0,1,1,1,1 }, // = 7
{ 0,0,0,0,0,0,0 }, // = 8
{ 0,0,0,1,1,0,0 }, // = 9
{ 1,1,1,1,1,1,1 }, // = 10 - Blank
{ 0,0,0,1,0,0,1 }, // = 11 - N
{ 0,0,0,1,0,0,0 }, // = 12 - R
{ 1,1,1,1,0,1,0 } // = 13 - r
};
int GEAR_1 = 10;
int GEAR_2 = 11;
int GEAR_3 = 12;
int GEAR_4 = 13;
int GEAR_5 = A0;
int GEAR_R = A1;
int gear_1 = HIGH;
int gear_2 = HIGH;
int gear_3 = HIGH;
int gear_4 = HIGH;
int gear_5 = HIGH;
int gear_R = HIGH;
int gear_N = HIGH;
void setup() {
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(GEAR_1, INPUT);
pinMode(GEAR_2, INPUT);
pinMode(GEAR_3, INPUT);
pinMode(GEAR_4, INPUT);
pinMode(GEAR_5, INPUT);
pinMode(GEAR_R, INPUT);
writeDot(1); // start with the "dot" off
}
void writeDot(byte dot) {
digitalWrite(9, dot);
}
void sevenSegWrite(byte digit) {
byte pin = 2;
for (byte segCount = 0; segCount < 7; ++segCount) {
digitalWrite(pin, seven_seg_digits[digit][segCount]);
++pin;
}
}
void loop() {
gear_1 = digitalRead(GEAR_1);
gear_2 = digitalRead(GEAR_2);
gear_3 = digitalRead(GEAR_3);
gear_4 = digitalRead(GEAR_4);
gear_5 = digitalRead(GEAR_5);
gear_R = digitalRead(GEAR_R);
if(gear_1 == LOW) {
sevenSegWrite(1);
} else if (gear_2 == LOW) {
sevenSegWrite(2);
} else if (gear_3 == LOW) {
sevenSegWrite(3);
} else if (gear_4 == LOW) {
sevenSegWrite(4);
} else if (gear_5 == LOW) {
sevenSegWrite(5);
} else if (gear_R == LOW) {
sevenSegWrite(13);
} else { // neutral
sevenSegWrite(10); // display Blank
writeDot(0); // using dot for Neutral, more discrete
}
delay(100);
}
thats the code that i am using but its for 6 sensors and now i want to use 4
thats the code that i am using but its for 6 sensors and now i want to use 4
So? What is the problem? Which two don't you want to use? Why can't you simply delete the code related to the other 2?
i want when pin 10 triggers to read 3 at the display
when pin 11 triggers to read 4 thats the easy.
now i want when pin 10 and 12 triggers to write 1
when pin 11 and 12 triggers to write 2
and pin 10 and 13 to write 5
and pin 11 and 13 to write r
Start by testing the combinations using if/else then test the single pins using more else clauses. That way you won't get false output when say pin 10 and 12 are triggered.