#include <avr/io.h>
#include <pololu/orangutan>
#include "Ping.h"
unsigned int Millivolts=0;
Ping PingSenor;
int main(void)
{
PingSenor.PingSensor(IO_C3);
Millivolts=OrangutanAnalog::readAverageMillivolts(0,1);
//calibrate Setpoint
while (inches<10)
{
PingSenor.PingSensor(IO_C3);
Setpoint=OrangutanAnalog::readAverageMillivolts(0,1);
if (Setpoint>0)
{
OrangutanDigital::setOutput(IO_D1,HIGH);
delay_ms(10);
}
OrangutanDigital::setOutput(IO_D1,LOW);
}
// mySetpoint=Setpoint;
// MaxSetpoint=mySetpoint+100;
// minSetpoint=mySetpoint-100;
/*Setpoint=699;*/
while(1)
{
Millivolts=OrangutanAnalog::readMillivolts(0);
if (Millivolts<Setpoint)
{
OrangutanDigital::setOutput(IO_D1,HIGH);
}
if (Millivolts>Setpoint)
{
OrangutanDigital::setOutput(IO_D1,LOW);
}
}
}
#include <avr/io.h>
#include <pololu/orangutan>
#include "Ping.h"
unsigned int Millivolts=0;
Ping PingSenor;
int main(void)
{
PingSenor.PingSensor(IO_C3);
Millivolts=OrangutanAnalog::readAverageMillivolts(0,1);
//calibrate Setpoint
while (inches<10)
{
PingSenor.PingSensor(IO_C3);
Setpoint=OrangutanAnalog::readAverageMillivolts(0,1);
if (Setpoint>0)
{
OrangutanDigital::setOutput(IO_D1,HIGH);
delay_ms(10);
}
OrangutanDigital::setOutput(IO_D1,LOW);
}
// mySetpoint=Setpoint;
// MaxSetpoint=mySetpoint+100;
// minSetpoint=mySetpoint-100;
/*Setpoint=699;*/
while(1)
{
Millivolts=OrangutanAnalog::readMillivolts(0);
if (Millivolts<(Setpoint-100))//here my problem
{
OrangutanDigital::setOutput(IO_D1,HIGH);
}
if (Millivolts>(Setpoint+100))//here is my problem
{
OrangutanDigital::setOutput(IO_D1,LOW);
}
}
}
all of the code that i have is below
#include <avr/io.h>
#include <pololu/orangutan>
#include "Ping.h"
unsigned int Millivolts=0;
int change=0;
#define motorspeed 255
unsigned int Setpoint=0;
int i=0;
Ping PingSenor;
bool corner=false;
bool stuck=false;
int Time=0;
int initialTime=0;
int finalTime=0;
int changeInTime=0;
int mySetpoint=Setpoint;
int changeSpeed=0;
int MaxSetpoint=0;
int minSetpoint=0;
void BITSHIFT(){
initialTime=Time;
change=255;
Millivolts=OrangutanAnalog::readAverageMillivolts(0,1);
change=Millivolts;
for(int m=0;m<25;m++){
change=(change>>i);
if(change ==0)m=25;
changeSpeed=255-(i+50);
i++;
}
//changeSpeed=255-i;
if((Millivolts)<(Setpoint-100)){
OrangutanDigital::setOutput(IO_D1,HIGH);
//OrangutanMotors::setSpeeds(changeSpeed,motorspeed);
}
if((Millivolts)>(Setpoint+100)){
//OrangutanMotors::setSpeeds(motorspeed,changeSpeed);
OrangutanDigital::setOutput(IO_D1,LOW);
}
if ((Millivolts>(Setpoint-100)&&(Setpoint+100)>Millivolts)&&(PingSenor.PingSensor(IO_C3)>=11))
{
//OrangutanMotors::setSpeeds(255,255);
OrangutanMotors::setSpeeds(0,0);
}
//
// if (inches<10)
// {
// OrangutanMotors::setSpeeds(255,-255);
// }
//
//
// if (PingSenor.PingSensor(IO_C3)<36&&PingSenor.PingSensor(IO_C3)>=10&&changeInTime>=10)
// {
// OrangutanMotors::setSpeeds(0,0);
// }
}
/*int CheckStatus(){
int initial=i;
if ()
{
}
finalTime=i;
}*/
int LeftWheel=255;
int rightWheel=255;
int decrease=0;
void testIRsensor(){
if (Millivolts<(Setpoint))
{
/*OrangutanMotors::setSpeeds(-255,255);*/
OrangutanDigital::setOutput(IO_D1,HIGH);
}
if (Millivolts>Setpoint)
{
OrangutanDigital::setOutput(IO_D1,LOW);
}
// if (Millivolts<(Setpoint-100))
// {
// OrangutanMotors::setSpeeds(255,-255);
// }
// else
// OrangutanMotors::setSpeeds(0,0);
}
void Corner(){
if (PingSenor.PingSensor(IO_C3)<10)
{
corner=true;
rightWheel=-255;
LeftWheel=255;
}
if (PingSenor.PingSensor(IO_C3)>10)
{
corner=false;
rightWheel=255;
LeftWheel=255;
}
OrangutanMotors::setSpeeds(rightWheel,LeftWheel);
}
void Tectic(){
Corner();
if (Millivolts>(Setpoint+100)&&corner==false)
{
decrease=decrease+10;
LeftWheel=LeftWheel-decrease;
}
if (Millivolts<(Setpoint-100)&&corner==false)
{
decrease=decrease+10;
rightWheel=rightWheel-decrease;
}
if (Millivolts<(Setpoint+100)&&Millivolts>(Setpoint-100)&&corner==false)
{
rightWheel=255;
LeftWheel=255;
decrease=0;
}
if (Millivolts>800&&corner==false)
{
OrangutanMotors::setSpeeds(255,-255);
}
}
int main(void)
{
PingSenor.PingSensor(IO_C3);
Millivolts=OrangutanAnalog::readAverageMillivolts(0,1);
//calibrate Setpoint
while (inches<10)
{
PingSenor.PingSensor(IO_C3);
Setpoint=OrangutanAnalog::readAverageMillivolts(0,1);
if (Setpoint>0)
{
OrangutanDigital::setOutput(IO_D1,HIGH);
delay_ms(10);
}
OrangutanDigital::setOutput(IO_D1,LOW);
}
// mySetpoint=Setpoint;
// MaxSetpoint=mySetpoint+100;
// minSetpoint=mySetpoint-100;
/*Setpoint=699;*/
while(1)
{
Millivolts=OrangutanAnalog::readMillivolts(0);
if (Millivolts<(Setpoint-100))//here my problem
{
OrangutanDigital::setOutput(IO_D1,HIGH);
}
if (Millivolts>(Setpoint+100))//here my problem
{
OrangutanDigital::setOutput(IO_D1,LOW);
}
}
}