I have been trying to use a digital light sensor as a switch to control two servos. If the input from the digital sensor is a 1, the servos will rotate, and if it is a zero, the servos will center (the instructions for the light sensor say that it will maintain a HIGH status when the power is on and fall to LOW status when light is detected. I have tried to configure pin A1 as a digital input and then read the value, but nothing seems to work. I haven't done any programming for years, and can't seem to find what I am looking for in any other posts.
I have an Axon MCU and have tried following the instructions in the following paragraph:
By default, all Axon digital ports are set as outputs (for use with servos). But you can also make them input pins.
First, you must declare the pin a digital input. Look at the file SoR_Utils.h for examples, and read the comments for instructions.
You can also do it quick and dirty in control.c like this:
cbi(DDRG, PG5); //set G5 as input pin
Then, just like in the button code, you'd want to read the pin:
bit_is_clear(PING, 5); //returns a 1 or 0
bit_is_set(PING, 5); //returns a 1 or 0"
This just isn't in depth enough for me, I guess. if I want to use A1 for this digital light sensor, I would use "cbi(DDRA, PA1); //set A1 as input pin" in control.c, correct? Where do I put the last two lines of code, and do i really need to use both lines (changing to "... (PINA, 1)")? What is the difference between them if the comments both say "returns a 1 or 0?
Finally, once I have the pin set as a digital input and have it returning a 1 or 0, how do I use this value in my code to control the servos? Specifically, do I need to define "light_sensor..." in hardware.c and then int light_sensor in control.c?
I hope this post makes sense; please help me out.