I've stared at this simple few lines of code for hours but I can't see what's wrong.
It's got to be syntax right?
I simply want to check a pin and then assign it's value to another variable name.
Checking the program with serialPrint though and all it gives me is the pin number.
I'm expecting a 1 or 0
Help please.
If you are wondering about the variables defined here that aren't used in this simple program. They are part of a much longer program, as will this bit of program when I get it working.
// defines how long events will occur
const long fanHigh = 30000; //how long to run fan high speed
// defines variables
const int fanPin = 5; //which pin is controling fan
long seqTimer = 0; //time between fan blasts
const int slow;
const int fast;
int fanSpeed;
long int fastDurr;
unsigned long seqStart = 0; //the time when the whole sequence began
unsigned long fan_HighTime = 0;//the time when fan was switched to High
unsigned long fastStart = 0; //time that fan was switched to high
long timeNow = 0;
//these are the defines for the sensor
const int detectPin = 6;//Pin connected to TTL
const int detect = 10; //Pin connected to LED &
int senState = HIGH; // senser initial state
int motion = 0; // variable High or LOW
void setup() {
Serial.begin(9600);
pinMode(fanPin,OUTPUT);// initialize digital pin 5 as an output for fan control.
int fanSpeed = 0; // starts fan at low speed
long int fastDurr = (timeNow - fastStart);
pinMode(detectPin, INPUT); // Sets the detect pin (6) as an Input
pinMode(detect, OUTPUT); //led indicator light
digitalWrite(detect,LOW); //start with red LED off
}
void loop() {
Serial.println("Top");
Serial.print(fanSpeed);
Serial.println(" fan speed");
timeNow = millis(); //remember current time
digitalRead(detectPin); //read pin 6
Serial.print(detectPin);
Serial.println(" detectPin");
Serial.println(" ");
fanSpeed = detectPin; //assign pin 6 value to "fanSpeed" variable
Serial.print(fanSpeed);
Serial.println(" fan speed");
Serial.println(" ");
delay(2000);
}