Need help joining colour sorting code and servos code. Help truly appreciated


hi all.

my name jeff , i'm new here.
for school project need build colour sorting robot can separate colour of balls. moment, use of arduino uno , tcs 3200 colour sensor  i had managed programme arduino in such way can read , recognise rgb value. of n object

with code this

code: [select]
#include <timerone.h>

#define s0     6
#define s1     5
#define s2     4
#define s3     3
#define out    2

int   g_count = 0;    // count frequecy
int   g_array[3];     // store rgb value
int   g_flag = 0;     // filter of rgb queue
float g_sf[3];        // save rgb scale factor


// init tsc230 , setting frequency.
void tsc_init()
{
 pinmode(s0, output);
 pinmode(s1, output);
 pinmode(s2, output);
 pinmode(s3, output);
 pinmode(out, input);

 digitalwrite(s0, low);  // output frequency scaling 2%
 digitalwrite(s1, high);
}

// select filter color
void tsc_filtercolor(int level01, int level02)
{
 if(level01 != 0)
   level01 = high;

 if(level02 != 0)
   level02 = high;

 digitalwrite(s2, level01);
 digitalwrite(s3, level02);
}

void tsc_count()
{
 g_count ++ ;
}

void tsc_callback()
{
 switch(g_flag)
 {
   case 0:
        serial.println("->wb start");
        tsc_wb(low, low);              //filter without red
        break;
   case 1:
        serial.print("->frequency r=");
        serial.println(g_count);
        g_array[0] = g_count;
        tsc_wb(high, high);            //filter without green
        break;
   case 2:
        serial.print("->frequency g=");
        serial.println(g_count);
        g_array[1] = g_count;
        tsc_wb(low, high);             //filter without blue
        break;

   case 3:
        serial.print("->frequency b=");
        serial.println(g_count);
        serial.println("->wb end");
        g_array[2] = g_count;
        tsc_wb(high, low);             //clear(no filter)  
        break;
  default:
        g_count = 0;
        break;
 }
}

void tsc_wb(int level0, int level1)      //white balance
{
 g_count = 0;
 g_flag ++;
 tsc_filtercolor(level0, level1);
 timer1.setperiod(1000000);             // set 1s period
}

void setup()
{
 tsc_init();
 serial.begin(9600);
 timer1.initialize();             // defaulte 1s
 timer1.attachinterrupt(tsc_callback);  
 attachinterrupt(0, tsc_count, rising);  

 delay(4000);

 for(int i=0; i<3; i++)
   serial.println(g_array[i]);

 g_sf[0] = 255.0/ g_array[0];     //r scale factor
 g_sf[1] = 255.0/ g_array[1] ;    //g scale factor
 g_sf[2] = 255.0/ g_array[2] ;    //b scale factor

 serial.println(g_sf[0]);
 serial.println(g_sf[1]);
 serial.println(g_sf[2]);

}

void loop()
{
  g_flag = 0;
  for(int i=0; i<3; i++)
   serial.println(int(g_array[i] * g_sf[i]));
  delay(4000);

}


but problem face after read colour rgb value how proceed make sorting part works 1 shown in link?

https://www.youtube.com/watch?v=cgvv-il5hti
and
https://www.youtube.com/watch?v=qv38ee_d-ny

please help
if me on sorting part of programming code above, appreciated.. new material needed  beside 1 follow. appreciated. in advance.

kind regards,
jeff


hi jeff
note in boolean algebra '!=0' same '=1' , same 'high', (0 = low), so
code: [select]
 if(level01 != 0)
   level01 = high;

does absolutely nothing. does
code: [select]
if(level02 != 0)
    level02 = high;
comment 4 lines out , you'll see makes no difference program.


Arduino Forum > Using Arduino > Project Guidance > Need help joining colour sorting code and servos code. Help truly appreciated


arduino

Comments

Popular posts from this blog

VIDIOC_S_FMT error 16, Device or resource busy - Raspberry Pi Forums

using a laptop skeleton to build a pi laptop - Raspberry Pi Forums

Forum for Joomla? - Joomla! Forum - community, help and support