Hi All,
I went through some libraries and did not udertand one basic thing. There are used lot of delay functions inside libraries. That means waiting preset time on one place in the program. So it doesn't depand how fast processor you have but you adding solid times to wait in the program. These delays adding together and made the main loop longer and longer. What is the way to use together for example step motor driving an LiquidCrystal and ultrasonic sensor SRF02? When I made it happened exactly I expected. The step motor ran discontinually due the delay functions in the code. Some things I changed into enhanced state machines but still there are a libraries with delay functions. May be I misunderstand your concept. How do you use it for controlling robots for example where are more than one axis and displays and many sensors? Do you use your own libraries made for real time application where you use state machines for cycle waiting? Or do you use interrupts for critical proceses to be more continuous?
Look what I mean:
Example one of functions for SRF02 (SRF02_Ultrasonic_sensor_(SKU_SEN0005)-DFRobot):
unsigned char SendCmd(unsigned char address,unsigned char cmd)
{
static unsigned char uc_t_done = 0;//externi casovac
Serial.write(address);//set the address of SRF02(factory default is 0)
delay(100);//serial data is fixed at 9600,N,8,2,so we need some time to creat the sencond stop bit
Serial.write(cmd);//send the command to SRF02
delay(100);//serial data is fixed at 9600,N,8,2,so we need some time to creat the sencond stop bit
return
}
Or Example of IIC on http://arduino.cc/en/Tutorial/SFRRangerReader:
...
Wire.write(byte(0x00)); // sets register pointer to the command register (0x00)
Wire.write(byte(0x50)); // command sensor to measure in "inches" (0x50)
// use 0x51 for centimeters
// use 0x52 for ping microseconds
Wire.endTransmission(); // stop transmitting
// step 2: wait for readings to happen
delay(70); // datasheet suggests at least 65 milliseconds
// step 3: instruct sensor to return a particular echo reading
Wire.beginTransmission(112); // transmit to device #112
...
Or Example of LicquidCrystal functions:
void LiquidCrystal::clear()
{
command(LCD_CLEARDISPLAY); // clear display, set cursor position to zero
delayMicroseconds(2000); // this command takes a long time!
}
void LiquidCrystal::home()
{
command(LCD_RETURNHOME); // set cursor position to zero
delayMicroseconds(2000); // this command takes a long time!
}
BR
Frank