Question about Orangutananalog::readMillivolt(channel)

Items I’m using:I’m using Ir sensor,ping sensor,cpp file avr 6.0, and orangutan 328

//Example 
int Setpoint=0;
millivolt=0; 
.....
void bitwise(){
    ....//the (...) is code that is Not relevant to my question. 
   if(millivolt>Setpoint)/*If i tried to add anything to Setpoint this code stop working.  My question is how can I a add value to  this SetPoint here....NOTE: The setpoint Automatic ..I want to give it a threshold..*/
     {
           ...
     }
....
}
 int main(){
     if(inches<10) //not relevant, but this set the setpoint
         Setpoint=Orangutan::readAvenageMillivolt(0,1);//this works is i planed it
       
  while(1){
          millivolt=Orangutan::readAvenageMillivolt(0,1);
      ......

}

can someone help me fix this, so if(millivolt>(Setpoint + 100)) will work?

In what way does the code “not work”?

Is this spelled correctly? [quote]readAvenageMillivolt(0,1)[/quote]

OrangutanAnalog::readAverageMillivolts(0, 1);
Sorry I didn’t copied my code, but i used the right spelling in the code…
I use too write code in .Cpp file instead of .c file.
So it will compile either analog_read_average_millivolts(0,1) or OrangutanAnalog::readAverageMillivolts(0, 1);…
So why doesn’t this work ( int max=OrangutanAnalog::readAverageMillivolts(0, 1)+100; )or( int maxanalog_read_average_millivolts(0,1)+100;)

Hi.

It is hard to offer any help without knowing what the problem you are seeing with the code is. How is the code not working? What output do you get, and what output do you expect to get? Do you get an error? Could you post the shortest complete version of your program that demonstrates the issue?

-Claire

I didn’t get any error or warning from the compiler , when i hit F4 on the keyboard…

It is hard for us to help without knowing in what way your code is not working.

-Claire

[code]
#include <pololu/orangutan>
#include <pololu/OrangutanDigital/OrangutanDigital.h>
#include <pololu/OrangutanMotors/OrangutanMotors.h>
#include <avr/io.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>
#include <pololu/OrangutanTime/OrangutanTime.h>

long inches;
int motorspeed;

class Ping{

public:
long LastHighPulseMicroseconds;

Ping(){ // !!!!
   inches=0;
   LastHighPulseMicroseconds=0;
   
}

~Ping(){

}

  void PingSensor(const unsigned char Ping2){
     
     //LastHighPulseMicroseconds=0;
     OrangutanDigital::setOutput(Ping2,LOW);
     OrangutanTime::delayMicroseconds(2);
     OrangutanDigital::setOutput(Ping2,HIGH);
     OrangutanTime::delayMicroseconds(5);
     OrangutanDigital::setOutput(Ping2,LOW);
     OrangutanPulseIn::start((unsigned char[]){Ping2},1);
     OrangutanDigital::setInput(Ping2,HIGH_IMPEDANCE);
     OrangutanTime::delayMilliseconds(25);
     
     LastHighPulseMicroseconds=OrangutanPulseIn::toMicroseconds(OrangutanPulseIn::getLastHighPulse(0));
     
    /* if(LastHighPulseMicroseconds>100)
     {
        OrangutanDigital::setOutput(IO_D1,LOW);
        delay(inches);
        OrangutanDigital::setOutput(IO_D1,HIGH);
        delay(inches);
        OrangutanDigital::setOutput(IO_D1,LOW);
     }*/
     
     
     //OrangutanPulseIn::stop();
     inches=LastHighPulseMicroseconds*.006699;
     delay_ms(100);
  }         

};
[/code]Ping.h

this code below doesn’t work

#include <avr/io.h>
#include <pololu/orangutan.h>
#include"Ping.h"//see my ping code on the forums
Ping sound;
int millivolt=0;
int Setpoint=0;
int main (){
    while (inches<12){
      sound.PingSensor(IO_3);
      millivolt=OrangutanAnalog::readAverageMillivolts(0, 1);
      Setpoint=millivolts;
    }
    while(1){
       if(millivolt >(Setpoint+100)
    {
     OrangutanDigital::setOutput(IO_D1,LOW);}
    if(millivolt<(Setpoint-100){
      OrangutanDigital::setOutput(IO_D1,HIGH);
}

      

}

The code below works

#include <avr/io.h>
#include <pololu/orangutan.h>
#include"Ping.h"//see my ping code on the forums
Ping sound;
int millivolt=0;
int Setpoint=0;
int main (){
    while (inches<12){
      sound.PingSensor(IO_3);
      millivolt=OrangutanAnalog::readAverageMillivolts(0, 1);
      Setpoint=millivolts;
    }
    while(1){
       if(millivolt >(Setpoint)
    {
     OrangutanDigital::setOutput(IO_D1,LOW);}
    if(millivolt<(Setpoint){
      OrangutanDigital::setOutput(IO_D1,HIGH);
}

      

}

It looks like your code has multiple missing or wrong brackets as well as some other typos in it. Are you sure that the last piece of code that you posted is working for you? Did you copy it directly from your program? If you want more help, you should post your full program as well as exactly what you are trying to accomplish with it. Also, tell us what you expect your code to do and what it is actually doing.

-Claire

[code]#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);
}
}
}[/code]

[code]
#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);
}
}
}[/code]
all of the code that i have is below

[code]

#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);
}
}
}[/code]




Thank you for posting your full program. However, in order to see if I can help you I also need a description of your problem. Just posting the code with a comment that says what line you are having an issue with is not enough for me to know what the actual issue is, and without knowing that, there is no way for me to know how to solve it. Could you try to tell me in as much detail as you can what you want your program to do and what it is actually doing? For example, does your program set D1 high when you think it should be setting it low? Does the code always give the wrong behavior, no matter what Setpoint and Millivolts are?

-Claire