Hi,
I'm a complete newbie so I would really appreciate if someone could help me.
I need to move a servo motor from o to 180 degrees and turn on and off a led depending on the amount of light (ldr resistor).
I've made the program for arduino, but I need to program it in C18 (MPLAB).
Arduino program:
________________________________________
const int sensor=0;
const int led=13;
int level,high=0,low=1023,angle=0;
#include <Servo.h>
Servo myservo;
void setup(){
pinMode(led,OUTPUT);
Serial.begin(9600);
myservo.attach(9);}
void loop(){
level=analogRead(sensor);
manualTune();
analogWrite(led,level);
int valueLDR;
valueLDR=analogRead(A0);
Serial.println(valueLDR);
if(valueLDR<500){
myservo.write(0);
delay(10);}
else{
myservo.write(180);}}
void manualTune(){
level=map(level,0,1023,0,255);
level=constrain(level,0,255);}
void autoTune(){
if (level<low){
low=level;}
else{
high=level;}
level=map(level,low+30,high-30,0,255);
level=constrain(level,0,255);}
________________________________________
(PS: I apologize for my bad english, it isn't my first language and i'm still learning.)