Interfacing of Colour Sensor using an IR sensor


dear all,

i doing project on interfacing color sensor arduino , output should display once when ir sensor tripped.

i have written whole code , working fine except small hitch cannot figure out , if else statement after satisfying condition of 1 output of time gives random outputs , last else statement keep on repeating till red,green or blue color found.

i grateful if me

thank
arjun warty

code: [select]
/*#include <wire.h> 
#include <liquidcrystal_i2c.h>
#include <servo.h>

liquidcrystal_i2c lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, positive);
*/

why should have wade past commented out code real code?

code: [select]
void setup()
{
serial.begin(115200);
pinmode(s0,output);
pinmode(s1,output);
pinmode(s2,output);
pinmode(s3,output);
pinmode(ir,input);
pinmode(13,output);
digitalwrite(13,low);
attachinterrupt(0,irinterrupt,rising);
/*lcd.begin(16,2);
lcd.backlight();
lcd.setcursor(0,0);
lcd.print("    arrangem    ");
lcd.setcursor(0,1);
lcd.print("      sbmp      ");
delay(2000);
lcd.setcursor(0,0);
lcd.print("  ashka ashani  ");
lcd.setcursor(0,1);
lcd.print(" deesha nirmal  ");
delay(2000);
lcd.setcursor(0,0);
lcd.print("  shaily sheth  ");
lcd.setcursor(0,1);
lcd.print("                ");
delay(2000);
lcd.setcursor(0,0);
lcd.print(" r  g  b  o  t  ");
lcd.setcursor(0,1);
lcd.print(" xx xx xx xx xx ");
serial.println(" r  g  b  o  t  ");
serial.println(" xx xx xx xx xx ");
*/
}

if can't bother indenting code, or using tools + auto format before posting it, why should bother reading it?

code: [select]
isr(timer2_ovf_vect)//the timer 2, 10ms interrupt overflow again.
//internal overflow interrupt executive function
{
tcnt2=0;
flag++;
if(flag==1)
{
countr=counter;
serial.print("red=");
serial.println(countr,dec);
digitalwrite(s2,high);
digitalwrite(s3,high);
}

serial output relies on interrupts. interrupts don't happen while on interrupt being processed. can not use serial.print() or serial.println() in isr.

code: [select]
for(int i=0;i<1000;i++)
{
  for(int i=0;i<1000;i++)
  tcnt2 = 0;
}

the compiler smarter you. tcnt2 set 0 once! using same name inner , outer loop indexes not indicative of being sharpest crayon in box.


Arduino Forum > Using Arduino > Programming Questions > Interfacing of Colour Sensor using an IR sensor


arduino

Comments

Popular posts from this blog

invalid use of void expresion in FlexiTimer2 library

error: a function-definition is not allowed here before '{' token

LED Strip Code