Okay. Just a simple question, say if i set pinMode(1, OUTPUT). And digitalRead(1), will it work?
Because if i do it like this in my code(Which is the somewhat the same as the example i given)
int led = 22;
int led1 = 24;
int led2 = 26;
int led3 = 28;
boolean DEBUG = true;
void setup() {
pinMode(led, OUTPUT); //pin selected to control
pinMode(led1, OUTPUT); //pin selected to control
pinMode(led2, OUTPUT); //pin selected to control
pinMode(led3, OUTPUT); //pin selected to control
pinMode(30, OUTPUT);
pinMode(32, OUTPUT);
pinMode(34, OUTPUT);
pinMode(36, OUTPUT);
pinMode(38, OUTPUT);
pinMode(40, OUTPUT);
pinMode(42, OUTPUT);
pinMode(44, OUTPUT);
pinMode(46, OUTPUT);
pinMode(48, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(A2, INPUT); //analog
pinMode(A3, INPUT); //analog
pinMode(A4, INPUT); //analog
pinMode(A5, INPUT); //analo
pinMode(A6, INPUT); //analog
pinMode(A7, INPUT); //analog
pinMode(A8, INPUT); //analog
pinMode(A9, INPUT); //analog
pinMode (2, INPUT); // For switch
pinMode (3, INPUT); // For switch
pinMode (5, INPUT); // For switch
pinMode (6, INPUT); // For switch
Serial.begin(9600);
}
void loop() {
Station1LED();
Station2LED();
Station3LED();
Station4LED();
if (DEBUG)
{
Serial.println("");
Serial.print("PIN 22 : ");
Serial.println(digitalRead(22));
Serial.print("PIN 24 : ");
Serial.println(digitalRead(24));
Serial.print("PIN 26 : ");
Serial.println(digitalRead(26));
Serial.print("PIN 28 : ");
Serial.println(digitalRead(28));
Serial.println("");
Serial.print("PIN 30 : ");
Serial.println(digitalRead(30));
Serial.print("PIN 32 : ");
Serial.println(digitalRead(32));
Serial.print("PIN 34 : ");
Serial.println(digitalRead(34));
Serial.print("PIN 36 : ");
Serial.println(digitalRead(36));
Serial.println("");
Serial.print("PIN 38 : ");
Serial.println(digitalRead(38));
Serial.print("PIN 40 : ");
Serial.println(digitalRead(40));
Serial.print("PIN 42 : ");
Serial.println(digitalRead(42));
Serial.print("PIN 44 : ");
Serial.println(digitalRead(44));
Serial.println("");
Serial.print("PIN 46 : ");
Serial.println(digitalRead(46));
Serial.print("PIN 48 : ");
Serial.println(digitalRead(48));
Serial.print("PIN 11 : ");
Serial.println(digitalRead(11));
Serial.print("PIN 12 : ");
Serial.println(digitalRead(12));
Serial.println("");
delay(1000);
}
}
void Station1LED()
{
if (digitalRead(2) == 0)
{
if (analogRead(A2) > 1 && analogRead(A3) > 900)
{
digitalWrite ( 22 , HIGH);
digitalWrite ( 24 , LOW);
digitalWrite ( 26 , LOW);
digitalWrite ( 28 , LOW);
}
else if(analogRead(A2) >= 100)
{
digitalWrite ( 22 , LOW);
digitalWrite ( 24 , LOW);
digitalWrite ( 26 , HIGH);
digitalWrite ( 28 , LOW);
}
else
{
digitalWrite ( 22 , LOW);
digitalWrite ( 24 , HIGH);
digitalWrite ( 26 , LOW);
digitalWrite ( 28 , LOW);
}
}
else
{
digitalWrite ( 22 , LOW);
digitalWrite ( 24 , LOW);
digitalWrite ( 26 , LOW);
digitalWrite ( 28 , HIGH);
}
}
void Station2LED()
{
if (digitalRead(3) == 0)
{
if (analogRead(A4) > 1 && analogRead(A5) > 900 )
{
digitalWrite ( 30 , HIGH);
digitalWrite ( 32 , LOW);
digitalWrite ( 34 , LOW);
digitalWrite ( 36 , LOW);
}
else if(analogRead(A4) >= 100)
{
digitalWrite ( 30 , LOW);
digitalWrite ( 32 , LOW);
digitalWrite ( 34 , HIGH);
digitalWrite ( 36 , LOW);
}
else
{
digitalWrite ( 30 , LOW);
digitalWrite ( 32 , HIGH);
digitalWrite ( 34 , LOW);
digitalWrite ( 36 , LOW);
}
}
else
{
digitalWrite ( 30 , LOW);
digitalWrite ( 32 , LOW);
digitalWrite ( 34 , LOW);
digitalWrite ( 36 , HIGH);
}
}
void Station3LED()
{
if (digitalRead(5) == 0)
{
if (analogRead(A6) > 1 && analogRead(A7) > 900 )
{
digitalWrite ( 38 , HIGH);
digitalWrite ( 40 , LOW);
digitalWrite ( 42 , LOW);
digitalWrite ( 44 , LOW);
}
else if(analogRead(A6) >= 100)
{
digitalWrite ( 38 , LOW);
digitalWrite ( 40 , LOW);
digitalWrite ( 42 , HIGH);
digitalWrite ( 44 , LOW);
}
else
{
digitalWrite ( 38 , LOW);
digitalWrite ( 40 , HIGH);
digitalWrite ( 42 , LOW);
digitalWrite ( 44 , LOW);
}
}
else
{
digitalWrite ( 38 , LOW);
digitalWrite ( 40 , LOW);
digitalWrite ( 42 , LOW);
digitalWrite ( 44 , HIGH);
}
}
void Station4LED()
{
if (digitalRead(6) == 0)
{
if (analogRead(A8) > 1 && analogRead(A9) > 900 )
{
digitalWrite ( 46 , HIGH);
digitalWrite ( 48 , LOW);
digitalWrite ( 11 , LOW);
digitalWrite ( 12 , LOW);
}
else if(analogRead(A8) >= 100)
{
digitalWrite ( 46 , LOW);
digitalWrite ( 48 , LOW);
digitalWrite ( 11 , HIGH);
digitalWrite ( 12 , LOW);
}
else
{
digitalWrite ( 46 , LOW);
digitalWrite ( 48 , HIGH);
digitalWrite ( 11 , LOW);
digitalWrite ( 12 , LOW);
}
}
else
{
digitalWrite ( 46 , LOW);
digitalWrite ( 48 , LOW);
digitalWrite ( 11 , LOW);
digitalWrite ( 12 , HIGH);
}
}
it doesnt actually work properly, some digitalRead() doesnt come out properly. For example LED connected to pin 1 is ON but the digitalRead(1) says it should be off.