Exemple #1
0
// This is the main loop
TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart) {

	// -------- Start Switch/Button-------
	// Switch/Button - see switch.h
	
	// To test if it is pressed then
	if(SWITCH_pressed(&button)){
		// pressed
	}
	
	// To test if it is released then
	if(SWITCH_released(&button)){
		// released
	}
	// -------- End   Switch/Button-------

	// -------- Start Marquee-------
	// Marquee - see 'segled.h'
	// Before using the Marquee you need to redirect rprintf to write to it
	// This can be done using
	Writer old = rprintfInit(marqueeGetWriter(&marquee));
	
	// All rprintf output will then be sent to the marquee but will not
	// display until an end-of-line eg "\n" has been sent. Example:-
	// rprintf("Hello World\n");
	
	// If the endDelay is non-zero then the marquee will scroll
	// forever or until you call: marqueeStop(&marquee);
	
	// If the endDelay is zero then the marquee will stop once
	// the entire line has been shown ('one-shot' mode)
	
	// In 'one-shot' mode then you may want to make sure that
	// a previous line has finished before you display a second line.
	// This can be done as follows:-
	marqueeSetEndDelay(&marquee,0); // Make sure we are in one-shot mode
	if(marqueeIsActive(&marquee)==FALSE){
	     if(loopCount==1){
	     	rprintf("ABCDEFGHIJKLMNOPQRSTUVWXYZ\n");
	     }else{
			rprintf("Loop=%u\n",(unsigned)loopCount); // Put the loop count
	     }
	}
	
	// Restore rprintf back to its previous location
	rprintfInit(old);
	// -------- End   Marquee-------

	// -------- Start Sharp GP2-------
	// Read the Sharp GP2 and store the result in ir_0.distance.cm
	distanceRead(ir_0);
	
	// The value can be printed using %u eg rprintf("Distance=%u",ir_0.distance.cm);
	// or dumped using:
	rprintf("ir_0: ");
	distanceDump(ir_0);
	rprintfCRLF();
	// -------- End   Sharp GP2-------

	// -------- Start Sharp GP2-------
	// Read the Sharp GP2 and store the result in ir_1.distance.cm
	distanceRead(ir_1);
	
	// The value can be printed using %u eg rprintf("Distance=%u",ir_1.distance.cm);
	// or dumped using:
	rprintf("ir_1: ");
	distanceDump(ir_1);
	rprintfCRLF();
	// -------- End   Sharp GP2-------

	// -------- Start Sharp GP2-------
	// Read the Sharp GP2 and store the result in ir_2.distance.cm
	distanceRead(ir_2);
	
	// The value can be printed using %u eg rprintf("Distance=%u",ir_2.distance.cm);
	// or dumped using:
	rprintf("ir_2: ");
	distanceDump(ir_2);
	rprintfCRLF();
	// -------- End   Sharp GP2-------

	// -------- Start Sharp GP2-------
	// Read the Sharp GP2 and store the result in ir_3.distance.cm
	distanceRead(ir_3);
	
	// The value can be printed using %u eg rprintf("Distance=%u",ir_3.distance.cm);
	// or dumped using:
	rprintf("ir_3: ");
	distanceDump(ir_3);
	rprintfCRLF();
	// -------- End   Sharp GP2-------

	// -------- Start Generic I2C Device-------
	// Read 3 register values starting at register 1 into response
	uint8_t lbRTOS_response[3];
	if(i2cMasterReadRegisters(&lbRTOS.i2cInfo, 1, sizeof(lbRTOS_response), lbRTOS_response)){
		// We have successfully read the data into 'lbRTOS_response'
	}else{
		rprintf("Failed reading lbRTOS\n");
	}
	// -------- End   Generic I2C Device-------

	return 0;
}
Exemple #2
0
// This is the main loop
TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart) {
	
	//Toggle mode via button
	if (!buttonWait){
		if(SWITCH_pressed(&button)){
			// pressed
			mode = (mode + 1) % NUMMODES;
			buttonWait = 1;
			buttonWaitStartTime = loopStart;
		
			// Clear vals for new mode
			for (int i=set; i < 14; i++){
				led[i].r = 0;
				led[i].g = 0;
				led[i].b = 0;
			}
			setLeds();
		}
	}
	// Wait 1 second after noticing a button press before allowing another button press
	else {
		if (clockHasElapsedGetOverflow(buttonWaitStartTime, buttonWaitTime, &unusedButtonRemainingTime)){
			buttonWait = 0;
		}
	}

	/// alternating half bright half fading
	if (mode == 1) {
		if (clockHasElapsedGetOverflow(switchtime, halfperiods[set], &remainingtime)) {
			// rprintf("boom!\n");
			delay_ms(400);
			// Switch modes if we've reached the end of increasing brightness
			if (dir == 1){
				set = (set + 1) % 2;
			}
			switchtime = clockGetus();
			dir *= -1;
			remainingtime = halfperiods[set] - remainingtime;
			
			// Set half the LEDs to maximum brightness
			for (int i=(1-set); i < 14; i+=2){
				// led[i].b = maxbright * 2;
				led[i].r = maxbright * 2;
				led[i].g = maxbright;
			}
		}
		
		// Calculate brightness of dimmer LEDs
		if(dir == 1){ // increasing brightness
			newbrightness = maxbright - (maxbright - minbright) * remainingtime / halfperiods[set];
		}
		else{ // decreasing brightness
			newbrightness = minbright + (maxbright - minbright) * remainingtime / halfperiods[set];
		}
		// Monocolor
		// newbrightness *= 2;
		// newbrightness += 1;
		
		for (int i=set; i < 14; i+=2){
			// blue
			// led[i].b = newbrightness;
			// orange
			led[i].r = newbrightness * 2 + 1;
			led[i].g = newbrightness + 1;
		}
		
		setLeds();
	}
	
	///
	else if (mode == 2) {
		if (clockHasElapsedGetOverflow(switchtime, halfperiods[set], &remainingtime)) {
			// rprintf("boom!\n");
			set = (set + 1) % 2;
			switchtime = clockGetus();
			remainingtime = halfperiods[set] - remainingtime;
		}
		
		for (int i=0; i < 14; i+=2){
			led[i].b = 0;
		}
		
		j = (14 * (remainingtime /1000))  / (halfperiods[set] / 1000);
		
		led[j].b = maxbright;
		
		setLeds();
	}
	
	/// moving orange
	else if (mode == 3) {
		if (clockHasElapsedGetOverflow(switchtime, halfperiods[set], &remainingtime)) {
			//delay_ms(250);
			// Switch modes if we've reached the end of increasing brightness
			//if (dir == 1){
			set = (set + 1) % 2;
			//}
			switchtime = clockGetus();
			//dir *= -1;
			remainingtime = halfperiods[set] - remainingtime;
		}
		
		for (int i=0; i < 14; i++){
			led[i].r = 0;
			led[i].g = 0;
			led[i].b = 0;
		}
		
		j = (14 * (remainingtime /1000))  / (halfperiods[set] / 1000);
		
		led[j].r = maxbright;
		led[j].g = maxbright/2;
		//led[j].b = maxbright;
		
		setLeds();
	}
	
	/// FLASHING WHITE
	else if (mode == 4) {
		if (clockHasElapsedGetOverflow(switchtime, halfperiods[set], &remainingtime)) {
			delay_ms(400);
			// Switch modes if we've reached the end of increasing brightness
			if (dir == 1){
				set = (set + 1) % 2;
			}
			switchtime = clockGetus();
			dir *= -1;
			remainingtime = halfperiods[set] - remainingtime;
			
		}
		
		// Calculate brightness
		if(dir == 1){ // increasing brightness
			newbrightness = maxbright - (maxbright - minbright) * remainingtime / halfperiods[set];
		}
		else{ // decreasing brightness
			newbrightness = minbright + (maxbright - minbright) * remainingtime / halfperiods[set];
		}
		
		for (int i=0; i < 14; i++){
			led[i].r = newbrightness * 2;
			led[i].g = newbrightness * 2;
			led[i].b = newbrightness * 2;
		}
		
		setLeds();
	}
	
	else if (mode == 5)
	{	
		k = (k+1)%w;
		y = 4;
		z = 7;
		w = 7;
		int val = (k*y)%z;
		// >>>  for k in xrange(w): print (k*y)%z;
		// for (int k=0; k < w; k+=x)
		// {
			// val = (k*y)%z;
		// }
		for (int i=0; i < 14; i++){
			led[i].r = maxbright * 2;
			led[i].g = maxbright;
			// led[i].b = newbrightness * 2;
		}
		led[val].r = maxbright * 2;
		led[val].g = maxbright * 2;
		
		led[val+7].r = maxbright * 3;
		led[val+7].g = maxbright * 2;
		
		setLeds();
		return 500000;
	}

	
	// ///////
	// // BlinkM control (doesn't work; probably need pull up resistors)
	// uint8_t blinkm_packet_setcolor[4];
	
	// blinkm_packet_setcolor[0] = (uint8_t)'n';
	// blinkm_packet_setcolor[1] = 50;
	// blinkm_packet_setcolor[2] = 50;
	// blinkm_packet_setcolor[3] = 50;
		
	// i2cMasterSend(&blinkm.i2cInfo, sizeof(blinkm_packet_setcolor), blinkm_packet_setcolor);
	// // i2cMasterSend(&blinkm.i2cInfo, sizeof(blinkm_packet_setcolor), *blinkm_packet_setcolor);
	// delay_ms(50);

	else if (mode == 0){
		
		for (int i=0; i < 14; i++){
			led[i].r = 0;
			led[i].g = 0;
			led[i].b = 0;
		}
		
		setLeds();	
	}
	
	return 20000;
}
Exemple #3
0
// This is the main loop
TICK_COUNT appControl(LOOP_COUNT loopCount, TICK_COUNT loopStart) {
	//rprintf("\t\t---------------------COUNTER: %d\n", counter);
	// -------- Start Switch/Button-------
	// Switch/Button - see switch.h
	
	// To test if it is pressed then
	if(SWITCH_pressed(&button)){
		// pressed
	}
	
	// To test if it is released then
	if(SWITCH_released(&button)){
		// released
	}
	// -------- End   Switch/Button-------

	// -------- Start Marquee-------
	// Marquee - see 'segled.h'
	// Before using the Marquee you need to redirect rprintf to write to it
	// This can be done using
	Writer old = rprintfInit(marqueeGetWriter(&marquee));
	
	// All rprintf output will then be sent to the marquee but will not
	// display until an end-of-line eg "\n" has been sent. Example:-
	// rprintf("Hello World\n");
	
	// If the endDelay is non-zero then the marquee will scroll
	// forever or until you call: marqueeStop(&marquee);
	
	// If the endDelay is zero then the marquee will stop once
	// the entire line has been shown ('one-shot' mode)
	
	// In 'one-shot' mode then you may want to make sure that
	// a previous line has finished before you display a second line.
	// This can be done as follows:-
	marqueeSetEndDelay(&marquee,0); // Make sure we are in one-shot mode
	if(marqueeIsActive(&marquee)==FALSE){
	     if(loopCount==1){
	     	rprintf("ABCDEFGHIJKLMNOPQRSTUVWXYZ\n");
	     }else{
			rprintf("Loop=%u\n",(unsigned)loopCount); // Put the loop count
	     }
	}
	
	// Restore rprintf back to its previous location
	rprintfInit(old);
	// -------- End   Marquee-------
/* FIGURE EIGHT TEST
	
	for(uint8_t i = 0; i < 90; i++){
		send_angle(cmd_r);
		delay_ms(62);
		rprintf("lb: %d\n",robot.sen_heading);
		cmd_r++;
	}
	for(uint8_t i = 0; i < 180; i++){
		send_angle(cmd_r);
		delay_ms(62);
		rprintf("lb: %d\n",robot.sen_heading);
		cmd_r--;
	}
	for(uint8_t i = 0; i < 90; i++){
		send_angle(cmd_r);
		delay_ms(62);
		rprintf("lb: %d\n",robot.sen_heading);
		cmd_r++;
	}
	
*/
//	rprintf("lb vel: %d\n",robot.sen_vel);
	//rprintf("MAIN LOOP\n");
//	lclz_plot();
	//ir_filter();
	send_angle(5);
	// -------- Start Sharp GP2------- // -90 degrees
	// Read the Sharp GP2 and store the result in ir_0.distance.cm
	//distanceRead(ir_0);
	//rprintf("P %d\n",robot.sen_heading);	
	// The value can be printed using %u eg rprintf("Distance=%u",ir_0.distance.cm);
	// or dumped using:
	//rprintf("ir_0: ");
	//distanceDump(ir_0);
	//rprintfCRLF();
	//x = (int)( (double)(ir_0.distance.cm / 2) * cos((-M_PI / 2) + robot.sen_heading) ) + 24;
	//y = (int)( (double)(ir_0.distance.cm / 2) * sin((-M_PI / 2) + robot.sen_heading) ) + 24;
	//g_map[x][y] = 1;
	//rprintf("%d,%d,1\n", x, y); //x, y,, intensity
	// -------- End   Sharp GP2-------

	// -------- Start Sharp GP2------- // 0 degrees
	// Read the Sharp GP2 and store the result in ir_1.distance.cm
	//distanceRead(ir_1);
	
	// The value can be printed using %u eg rprintf("Distance=%u",ir_1.distance.cm);
	// or dumped using:
	//rprintf("ir_1: ");
	//distanceDump(ir_1);
	//rprintfCRLF();
	//x = (int)( (double)(ir_1.distance.cm / 2) * cos(0 + robot.sen_heading) ) + 24;
	//y = (int)( (double)(ir_0.distance.cm / 2) * sin(0 + robot.sen_heading) ) + 24;
	//g_map[x][y] = 1;
	//rprintf("%d,%d,1\n", x, y);//x, y,, intensity
	// -------- End   Sharp GP2-------




	// -------- Start Sharp GP2------- // 90 degrees
	// Read the Sharp GP2 and store the result in ir_2.distance.cm
	//distanceRead(ir_2);
	
	// The value can be printed using %u eg rprintf("Distance=%u",ir_2.distance.cm);
	// or dumped using:
	//rprintf("ir_2: ");
	//distanceDump(ir_2);
	//rprintfCRLF();
	//x = (int)( (double)(ir_2.distance.cm / 2) * cos((M_PI / 2) + robot.sen_heading) ) + 24;
	//y = (int)( (double)(ir_2.distance.cm / 2) * sin((M_PI / 2) + robot.sen_heading) ) + 24;
	//g_map[x][y] = 1;
	//rprintf("%d,%d,1\n", x, y);//x, y,, intensity
	// -------- End   Sharp GP2-------
/**/
	// -------- Start Sharp GP2------- //45 degrees
	// Read the Sharp GP2 and store the result in ir_3.distance.cm
	//distanceRead(ir_3);
	
	// The value can be printed using %u eg rprintf("Distance=%u",ir_3.distance.cm);
	// or dumped using:
	//rprintf("\tir_3: ");
	//distanceDump(ir_3);
	//rprintfCRLF();
	// -------- End   Sharp GP2-------
	
	//-45 degrees
	//distanceRead(ir_4);
	//rprintf("\tir_4: ");
	//distanceDump(ir_4);

	//iter += 0.02;
	//print_map();
	counter++;
	return 0;
}