Hi All,
I hoped I posted this on the correct forum. I am not sure whether I should post it in this forum or other microcontroller forum.
I use Sharp IR Sensor Long Range (Sharp GP2Y0A02YK0F) on ATTiny 45.
I just want to use the sensor to detect if there is any object in front of it.
My code works on Arduino, but it did not work on ATTiny45. Can anyone please advise how should I do the coding for analog input from proximity sensor on ATTiny45?
const int CONTROL1 = 0;
const int CONTROL2 = 1;
const int proxSensor = A2; // input from Infrared proximity sensor
void setup() {
// put your setup code here, to run once:
pinMode(CONTROL1, OUTPUT);
pinMode(CONTROL2, OUTPUT);
pinMode(proxSensor, INPUT);
}
void loop() {
int proxSensorVal = analogRead (proxSensor);
if (proxSensorVal >= 200){
digitalWrite (CONTROL1, HIGH);
digitalWrite (CONTROL2, LOW);
}
else if (proxSensorVal<200){
digitalWrite (CONTROL1, LOW);
digitalWrite (CONTROL2, HIGH);
}
Thanks