Society of Robots - Robot Forum

Software => Software => Topic started by: Roboteccan on November 06, 2010, 03:27:08 PM

Title: how detect black and white color?
Post by: Roboteccan on November 06, 2010, 03:27:08 PM
hi, we are making a SumoRobot, and we need that detect white and black color, we are using the AVR studio 4 software and axon microcontroller hardware, and a CNY70 sensor, but the AVR dont have library of CNY70 sensor and I dont know how conect and I dont know how program this sensor, this is my code.

#include<avr/IO.h>
#include "sys/axon.h"

DDRA = 0xFF;

void appInitHardware(void){
pin_make_output(C0, TRUE);
pin_make_input(A0, TRUE);
}

TICK_COUNT appInitSoftware(TICK_COUNT loopStart){
    return 0;
}

TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart) {

if (pin_is_high(A0)){
pin_is_high(C0);
}
else{
pin_is_low(C0);
}
   return 1;
}

please help me.
Title: Re: how detect black and white color?
Post by: Admin on November 11, 2010, 10:30:48 AM
To connect, you should first look at the datasheet:
http://www.vishay.com/docs/83751/cny70.pdf (http://www.vishay.com/docs/83751/cny70.pdf)
and look at the picture in the top left.

Then you want to follow the top schematic here:
http://www.societyofrobots.com/schematics_infraredemitdet.shtml (http://www.societyofrobots.com/schematics_infraredemitdet.shtml)
(read the entire tutorial)

The IR sensor uses an LED, so use this tutorial to select your LED resister (R1):
http://www.societyofrobots.com/electronics_led_tutorial.shtml (http://www.societyofrobots.com/electronics_led_tutorial.shtml)

And use this tutorial to select the resister on the sensor (R2):
http://www.societyofrobots.com/schematics_photoresistor.shtml (http://www.societyofrobots.com/schematics_photoresistor.shtml)

A little more reading to understand what's going on:
http://www.societyofrobots.com/sensors_color.shtml (http://www.societyofrobots.com/sensors_color.shtml)

Now in code, you want to use the analog sensor code in WebbotLib, with the device plugged into the ADC header of your Axon.