Exemple #1
37
uint8_t SetAll(uint8_t m1,uint8_t m2) {
	uint8_t v1,v2;

	SetOne1K(m1&0x03);
	SetTwo1K((m1>>2)&0x03);
	SetThree1K((m1>>4)&0x03);
	SetOne300K(m2&0x03);
	SetTwo300K((m2>>2)&0x03);
	SetThree300K((m2>>4)&0x03);

	adc1=AnalogRead(ONEADC);	
	adc2=AnalogRead(TWOADC);	
	adc3=AnalogRead(THREEADC);

	v1=128;v2=128;
	if ((m2&0b00000011)>0) {v1=adc2;v2=adc3;}
	if ((m2&0b00001100)>0) {v1=adc1;v2=adc3;}
	if ((m2&0b00110000)>0) {v1=adc1;v2=adc2;}
	if (v1>v2) return (v1-v2); 
	else return (v2-v1);

}
Exemple #2
8
void setup()
{

	initBoard();
	while(true)
	{
		if((AnalogRead(MIDDLE)<50))
		{
			initdisplay();display.println("MIDDLE");display.display();
			forward(100);
			delay(1000);
			stop();
			delay(1000);
		}
		else
		{
		}
		if((AnalogRead(LEFT)<50))
		{
			initdisplay();display.println("LEFT");display.display();
			left(50);
			delay(1000);
			stop();
			delay(1000);
		}
		else
		{
		}
		if((AnalogRead(RIGHT)<50))
		{
			initdisplay();display.println("RIGHT");display.display();
			right(50);
			delay(1000);
			stop();
			delay(1000);
		}
		else
		{
		}
	}
}
void setup()
{
	initBoard();

	float s0 = 0;
	while(true)
	{
		s0 = AnalogRead(sensor0);
		DigitalWrite(D13_LED, true);
		delay((s0*5));
		DigitalWrite(D13_LED, false);
		delay((s0*5));
	}
}
void AquireImage() // Read TSL1401 chip into sample array
{
  uint8  i;
	uint16 d;
	asm("di");  // timing critical area, disable any interrupts!
	BACKLIGHT(ON);
	// 1. clock out crap as fast as possible (see TSL1401 documentation or parallax TLS1401 developer board is better) 2uS x 128 = 256uS
	SI(ON);
	for(i=0;i<129;i++)
	{
		CLK(ON);
		DelayMicroseconds(1);
		SI(OFF);
		CLK(OFF);
		DelayMicroseconds(1);
		if(i>exposure) BACKLIGHT(OFF);
	}
	// 2. Wait for exposure to finish if its greater than 128
  if(exposure>128) DelayMicroseconds(exposure-128);
	BACKLIGHT(OFF); // turn off the backlight
	// 3. Second pass, clock out the real data into raw buffer for processing and also average samples and put in sample array
	SI(ON);
	asm("ei");
	for(i=127; i>0; i--) // sensor is inverted 180 deg because of lens so top is bottom and bottom is top so do this backwards or turn chip around on pcb!
	{
		CLK(ON);
		DelayMicroseconds(1);
		SI(OFF);
		d = AnalogRead(ANA);
		if(d>MAXBRIGHTNESS)	RawData[i]=MAXBRIGHTNESS; else RawData[i]=d;  // 255 is Max value we can get from TSL1401, but we have 10 bit ADC in PIC32 so we need to clip
	  if(SampleCount<MAXSAMPLES && SampleCount>2) AccumulatedData[i] = AccumulatedData[i] + RawData[i]; // accumulate total light across width of bottle so we can get an avg
		CLK(OFF);
		DelayMicroseconds(1);
	}
	if(SampleCount<MAXSAMPLES) SampleCount++; // increment how many samples in accumulator
	CLK(ON);
	DelayMicroseconds(1);
	CLK(OFF);
	if(SampleRate - 1500 > exposure)
	  DelayMicroseconds(SampleRate - 1500 - exposure); // hard-code delay so we get correct sample rate
}
Exemple #5
-18
void setup()
{
	initBoard();
	float senValue = 0;
	while(true)
	{
		senValue = AnalogRead(sensor0);
		if((senValue<33))
		{
			AnalogWrite(PWM9, senValue);
			AnalogWrite(PWM10, 0);
			AnalogWrite(PWM11, 0);
		}
		else
		{
			if((senValue<66))
			{
				AnalogWrite(PWM9, 0);
				AnalogWrite(PWM10, senValue);
				AnalogWrite(PWM11, 0);
			}
			else
			{
				AnalogWrite(PWM9, 0);
				AnalogWrite(PWM10, 0);
				AnalogWrite(PWM11, senValue);
			}
		}
		delay(300);
	}
}