Example #1
0
static void _hModeSettings()
{
	NOKEYRETURN;
	elementKey(5);
	if (KEY4)	// CHANGE?
	{
		if (elementIndex == 0) Config.SelfLevelMode = (Config.SelfLevelMode + 1) % 3;
		else if (elementIndex == 1) Config.ArmingMode = !Config.ArmingMode;
		else if (elementIndex == 2) Config.LinkRollPitch = !Config.LinkRollPitch;
		else if (elementIndex == 3) Config.AutoDisarm = !Config.AutoDisarm;
		else Config.ReceiverMode = !Config.ReceiverMode; rxInit(Config.ReceiverMode);
		//configSave();
	}
	
	const char* str;
	if (Config.SelfLevelMode == SELFLEVEL_ON) str = strOn;
	else if (Config.SelfLevelMode == SELFLEVEL_AUX) str = strAUX;
	else str = strStick;
	
	writeString_P(0, 84, str, 5, 0);
	writeString_P(1, 84, Config.ArmingMode ? strOn : strStick, 5, 1);
	writeString_P(2, 102, Config.LinkRollPitch ? strYes : strNo, 3, 2);
	writeString_P(3, 84, Config.AutoDisarm ? strYes : strNo, 3, 3);
	writeString_P(4, 84, Config.ReceiverMode ? strYes : strNo, 3, 4);
}
Example #2
0
void test(uint8_t number)
{
	bars(2);
	writeString_P("#### TEST #");
	writeInteger(number, DEC);
	writeString_P(" ####\n");
}
Example #3
0
int main(void)
{
	initRobotBase(); // Always call this first! The Processor will not work
					 // correctly otherwise. 
	
    writeString_P("\nRP6 Stopwatch Demo Program\n");
	writeString_P("__________________________\n\n");

	// Start all used Stopwatches:
	startStopwatch1();
	startStopwatch2();
	startStopwatch3();
	startStopwatch4();

	// Set a stopwatch to a specific initial value:
	setStopwatch2(1600);
	
	// Main loop
	while(true) 
	{
		// Here we call the four "tasks" we have.
		// You should poll each stopwatch
		// in it's own function like it is done here, this keeps the sourcecode 
		// a bit more tidy. (In the RP6 Manual you can find an example
		// which has this within the main method)
		task_LEDs();
		task_counter1();
		task_counter2();
		task_counter3();
	}
	return 0;
}
void Event( int x ){

	switch(x){
	
		case 0: { writeString_P("\n Nothing "); break;}
		case 1: { Pos_Servo_1--; mSleep(speed); break;}
		case 2: { Pos_Servo_1++; mSleep(speed); break;}
		case 3: { Pos_Servo_2--; mSleep(speed); break;}
		case 4: { Pos_Servo_2++; mSleep(speed); break;}
		case 5: { Pos_Servo_3--; mSleep(speed); break;}
		case 6: { Pos_Servo_3++; mSleep(speed); break;}
		case 7: { Pos_Servo_4--; mSleep(speed); break;}
		case 8: { Pos_Servo_4++; mSleep(speed); break;}
		case 9: { Pos_Servo_5--; mSleep(speed);break;}
		case 10: {  Pos_Servo_5++; mSleep(speed);break;}
		case 11: {  Pos_Servo_6--; mSleep(speed);break;}
		case 12: {  Pos_Servo_6++; mSleep(speed);break;}
		case 13: { writeString_P("\n TANK FNT"); break;}
		case 14: { writeString_P("\n TANK BCK"); break;}
		case 15: { writeString_P("\n TANK RIGHT"); break;}
		case 16: { writeString_P("\n TANK LEFT"); break;}
		
	}

}
Example #5
0
void ShowDataReceivedOverUART( void )
{
	char receiveBuffer[RECEIVE_BUFFER_SIZE];
	uint8_t nrOfCharsReceived = getBufferLength();
	
	// check if no data was received
	if (nrOfCharsReceived == 0) return;

	int index = 0;
	while(getBufferLength() > 0) {
		receiveBuffer[index] = readChar();
		index++;

		//- reserve the last character of the buffer for '\0' character
		//- check not to write outside array boundaries.	
		if (index > (RECEIVE_BUFFER_SIZE -2)) 
		{
			break;
		}
	}

	receiveBuffer[index] = '\0';

	writeString_P("Echo: ");
	writeString(receiveBuffer);
}
Example #6
0
int main(void)
{
	initRobotBase(); // Always call this first! 
	                  // The Processor will not work correctly otherwise.
					 
	// Write a text message to the UART:
	writeString_P("\nCounting and Receiving\n");
	
	// Define a counting variable:
	uint16_t counter = 0;
	
	// clear the UART buffer once at the start of the program
	clearReceptionBuffer();
	
	while(true)
	{
		// example of sending some data over UART
		counter++;    
		SendDataOverUART(counter);

		//example of receiving some data over UART
		ShowDataReceivedOverUART();
		
		mSleep(100); // delay 100ms = 0.1s
	}
	return 0;
}
Example #7
0
/**
 * This function gets called automatically if there was an I2C Error like
 * the slave sent a "not acknowledge" (NACK, error codes e.g. 0x20 or 0x30).
 */
void I2C_transmissionError(uint8_t errorState)
{
	writeString_P("\n############ I2C ERROR!!!!! - TWI STATE: 0x");
	writeInteger(errorState, HEX);
	writeChar('\n');
	errors++;
}
int main(void)
{
	initRobotBase(); 	// Always call this first! The Processor will not work
						// correctly otherwise.		 
	mSleep(1000);        // delay 1s

	speed = 0; //Speed for servo from '0'(fast) - '10'(slow)

	writeString_P("\n Key Board Control \n\n");

	Start_position(); //Use this function to set the servomotor in the centre. 
					  //This function must be called before using Power_Servos();
	
	Power_Servos();  //Use this function to power the servo motors on
					 //When you want to power off the servos, you need to call function Power_Off_Servos();
	
	
	// ---------------------------------------
	// Main loop:
	while(true)
	{
		
		Event(scan_keyboard());
		
	// End of main loop!
	// ---------------------------------------
	}
	return 0;
}
Example #9
0
void SendDataOverUART(int value)
{
	// These functions send data over the UART
	writeString_P("Counter: "); 

	writeInteger(value, DEC);
	writeString_P("(DEC) | ");

	writeInteger(value, HEX);
	writeString_P("(HEX) | ");
	
	writeInteger(value, BIN);
	writeString_P("(BIN) ");

	writeChar('\n'); // New Line
}
Example #10
0
static void _hMixerEditor()
{
	NOKEYRETURN;
		
	if (KEY4)	// CHANGE?
	{
		if (elementIndex == 0)
			subpage = (subpage + 1) % length(Config.Mixer);
		else if (elementIndex <= 5)
		{
			startEditMode(&Config.Mixer[subpage].I8[elementIndex - 1], -127, 127, TYPE_INT8); 
			return;
		}						
		else if (elementIndex == 6)		// type
		{
			if (Config.Mixer[subpage].Flags == 0)
				Config.Mixer[subpage].Flags = FLAG_ESC | FLAG_HIGH;
			else if (Config.Mixer[subpage].IsMotor)
				Config.Mixer[subpage].Flags = FLAG_SERVO;
			else 
				Config.Mixer[subpage].Flags = FLAG_NONE;
		}		
		else
			Config.Mixer[subpage].Flags ^= FLAG_HIGH;
	}
	
	elementKey(8);
	writeValue(0, 120, subpage + 1, 1, 0);
	for (uint8_t i = 0; i < 5; i++)
		writeValue(i, 60, Config.Mixer[subpage].I8[i], 4, i + 1);
	const char *s;
	
	if (Config.Mixer[subpage].IsMotor)
		s = strESC;
	else if (Config.Mixer[subpage].IsServo)
		s = strServo;
	else
		s = strOff;
		
	writeString_P(5, 36, s, 5, 6);
	writeString_P(5, 108, Config.Mixer[subpage].IsMotor || Config.Mixer[subpage].IsHiRate ? strHigh : strLow, 3, 7);
}
Example #11
0
/**
 * A second counter, with different interval (0.8s) and
 * binary output format. 
 */
void task_counter2(void)
{
	static uint8_t counter2;
	if(getStopwatch3() > 800) // 800ms = 0.8s
	{
		writeString_P("\t  CNT2 : ");
		writeInteger(counter2, BIN);
		writeChar('\n');
		counter2++;
		setStopwatch3(0); // Reset stopwatch
	}
}
Example #12
0
/**
 * A simple counter that outputs it's value on the
 * Serialport each time it is incremented. 
 * It is incremented every 400ms.
 */
void task_counter1(void)
{
	static uint8_t counter;
	if(getStopwatch2() > 400) // 400ms = 0.4s
	{
		writeString_P("CNT1 : ");
		writeInteger(counter, DEC);
		writeChar('\n');
		counter++;
		setStopwatch2(0); // Reset stopwatch
	}
}
Example #13
0
/**
 * A third counter, with different interval (1.2s) and
 * hexadecimal output format. 
 */
void task_counter3(void)
{
	static uint8_t counter2;
	if(getStopwatch4() > 1200) // 1200ms = 1.2s
	{
		writeString_P("\t\t        CNT3 : ");
		writeIntegerLength(counter2, HEX, 2);
		writeChar('\n');
		counter2++;
		setStopwatch4(0); // Reset stopwatch
	}
}
Example #14
0
void ir_init(void)
{
    receive_buffer[0] = 2;
    receive_buffer[1] = 17;
    receive_buffer[2] = 32;
    receive_buffer[3] = 45;
    receive_buffer[4] = 7;
    receive_buffer[5] = 23;
    receive_buffer[6] = 33;
    receive_buffer[7] = 41;


    SPI_EEPROM_writeByte(schrijf, receive_buffer[0]);
    mSleep(50);
    SPI_EEPROM_writeByte(schrijf+1, receive_buffer[1]);
    mSleep(50);
    SPI_EEPROM_writeByte(schrijf+2, receive_buffer[2]);
    mSleep(50);
    SPI_EEPROM_writeByte(schrijf+3, receive_buffer[3]);
    mSleep(50);
    schrijf = (schrijf + 8);

    SPI_EEPROM_writeByte(schrijf, receive_buffer[4]);
    mSleep(50);
    SPI_EEPROM_writeByte(schrijf+1, receive_buffer[5]);
    mSleep(50);
    SPI_EEPROM_writeByte(schrijf+2, receive_buffer[6]);
    mSleep(50);
    SPI_EEPROM_writeByte(schrijf+3, receive_buffer[7]);
    mSleep(50);
    schrijf = (schrijf + 8);

    ir_sendSituation(NORTH, 1, 2);


    SPI_EEPROM_writeByte(schrijf, 5);
    mSleep(50);
    SPI_EEPROM_writeByte(schrijf+1, 21);
    mSleep(50);
    SPI_EEPROM_writeByte(schrijf+2, 34);
    mSleep(50);
    SPI_EEPROM_writeByte(schrijf+3, 47);
    mSleep(50);


    writeString_P("Stuff 'n Stuff\n");

    while (true) {
        ir_sendBaseStation();
    }
}
Example #15
0
int main(void)
{
	initRP6Control(); // Always call this first! The Processor will not work
					  // correctly otherwise. 

	initLCD(); // Initialize the LC-Display (LCD)
		   // Always call this before using the LCD!
			   
	writeString_P("\n\nRP6 CONTROL: C-code examples\n"); 
	showScreenLCD("C Code examples", "     ....");

	run_testCases();
	
	return 0;
}
Example #16
0
int main(void)
{
	question = 0;
	
	initRobotBase(); // Always call this first! The Processor will not work
					 // correctly otherwise.
	
	Leds_Beeper();
	
	writeString_P("\nHello! My name is RobotArmy\n");
	
	while(true)
	{
	if(question != -1)
			askAQuestion();
	
	}
	return 0;
}
Example #17
0
int main(void)
{
	initRobotBase(); // Always call this first! The Processor will not work
					 // correctly otherwise.
					 
	setLEDs(0b111111); // Turn all LEDs on
	mSleep(500);       // delay 500ms
	setLEDs(0b000000); // All LEDs off

	// Write a text message to the UART:
	writeString_P("\nJust a simple counter program\n\n");
	
	// Define a counting variable:
	uint16_t counter = 0;
	
	// ---------------------------------------
	// Main loop:
	while(true)
	{
		timer = 0; // initialize universal timer variable for measuring how much
				   // time the output required! (this is not directly related to this
				   // example - it was added as a small example for the new System
				   // timer added in Version 1.3 of the RP6Lib)
				   // The timer has a resolution of 100µs and runs all the time. 
		
		// Now we check what value the counter has, ...
		if(counter < 100) // ... is it smaller than 100?
		{
			// Yes --> output the Counter value with the "writeInteger"
			// function:
			writeString_P("Counter: "); 
			writeInteger(counter, BIN);
			writeString_P("(BIN) | ");
			writeInteger(counter, OCT);
			writeString_P("(OCT) | ");
			writeInteger(counter, DEC);
			writeString_P("(DEC) | ");
			writeInteger(counter, HEX);
			writeString_P("(HEX) ");
		}
		else 			  // ... or is it greater than or equal to 100?
		{
			// No, the counter >= 100 --> use "writeIntegerLength" instead.
			writeString_P("Counter L: ");
			writeIntegerLength(counter, BIN, 16);  
			writeString_P("(BIN) | ");
			writeIntegerLength(counter, OCT, 6);
			writeString_P("(OCT) | ");
			writeIntegerLength(counter, DEC, 6);
			writeString_P("(DEC) | ");
			writeIntegerLength(counter, HEX, 4);
			writeString_P("(HEX) ");
		}
		writeChar(' ');
		writeInteger(timer,DEC); // display time (in 100µs) we needed for this output!
								 // You will directly see that the time increases when
								 // the output gets longer.
		writeString(" *100us");
		
		writeChar('\n'); // New Line
		
		counter++;    // Increment counter
		
		mSleep(100); // delay 200ms = 0.2s
	}
	// End of main loop!
	// ---------------------------------------

	return 0;
}
Example #18
0
int main(void)
{
	initRP6Control(); // Always call this first! 
	                  // The Processor will not work correctly otherwise.
					 
	initLCD(); // Initialize the LC-Display (LCD)
			   // Always call this before using the LCD!

	// Play two sounds with the Piezo Beeper on the RP6Control:
	sound(180,80,25);
	sound(220,80,0);
	
	//IMPORTANT:
	I2CTWI_initMaster(100); // Initialize the TWI Module for Master operation
	// with 100kHz SCL Frequency
	
	// Register the event handlers:
	I2CTWI_setTransmissionErrorHandler(I2C_transmissionError);

	// Write a text message to the UART:
	writeString_P("{cmd=0x");
	writeInteger(CMD_LIFETIME, HEX);
	writeString_P("}\n");
	
	run_testCases();
	
	// Define a counting variable:
	//uint16_t counter = 0;
	
	// clear the UART buffer once at the start of the program
	clearReceptionBuffer();
	
	
	mSleep(1000);
	
	setStopwatch1(500);
	startStopwatch1();
	
	while(true)
	{
		//example of receiving some data over UART
		DoDataProcess();
		
		if(move_turning!=0)
		{
			if(move_turning == 1)
			{
				rotate(60, LEFT, 3, false);
			}
			else
			{
				rotate(60, RIGHT, 3, false);
			}
		}
		else		
		if(move_horizontal != 0)
		{
			if(move_horizontal > 0)
			{
				move(move_horizontal, FWD, 3, false);
			}
			else
			{
				move(move_horizontal, BWD, 3, false);
			}
		}
		
		//mSleep(100); // delay 100ms = 0.1s
	}
	return 0;
}
Example #19
0
int main(void)
{
	initRobotBase(); // Always call this first! The Processor will not work
					 // correctly otherwise.

	// ---------------------------------------
	// Write messages to the Serial Interface
	// (here it is a RP6 text logo):
	writeString_P("\n\n   _______________________\n");
	writeString_P("   \\| RP6  ROBOT SYSTEM |/\n");
	writeString_P("    \\_-_-_-_-_-_-_-_-_-_/\n\n");

	// Explanation of special chars:
	// '\n' = new line
	// '\\' = '\'
	// These are "escape sequences" for characters you can not
	// use directly within strings.

	// Write "Hello World" to the Serial Interface:
	writeString_P("Hello World! My name is Robby!\n");
	writeString_P("Let's go! :)\n");
	
    

	// ---------------------------------------
	// LEDs:
	setLEDs(0b111111); // Turn all LEDs on!

	// 0b111111 is a binary value and is the same as
	// 63 in the decimal system.
	// For this routine, the binary value is better to read, because each bit
	// represents one of the LEDs.
	// e.g. this:
	// setLEDs(0b000001); would set only LED1
	// setLEDs(0b000010); LED2
	// setLEDs(0b000100); LED3
	// setLEDs(0b101001); LED6, LED4, LED1 - and so on!

	mSleep(1000); // delay 1000ms = 1s
	setLEDs(0b000000); // All LEDs off!
	mSleep(500); // delay 500ms = 0.5s


	// ---------------------------------------

	uint8_t runningLight = 1; // This defines the local unsigned 8 bit variable "runningLight".
						      // It can be accessed everywhere _below_ in this function.
						      // And ONLY within this function!

	// ---------------------------------------
	// Main loop - the program will loop here forever!
	// In this program, it only runs a small LED chaselight.
	while(true)
	{
		// Here we do a small LED test:
		// ---------------------------------------

		setLEDs(runningLight); 	// Set status LEDs to the value of the variable
							// testLEDs.
							// In the first loop iteration it has the value 1,
							// and thus the StatusLED1 will be switched on.

		runningLight <<= 1; // shift the bits of "runningLight" one step to the left.
						// As there is only one bit set in this variable,
						// only one LED is on at the same time.
						// This results is a moving light dot like this:
						// 1: 0b000001
						// 2: 0b000010
						// 3: 0b000100
						// 4: 0b001000
						// 5: 0b010000
						// 6: 0b100000 
						//
						// In decimal format that would be the numbers:
						// 1, 2, 4, 8, 16, 32

		// When we have reached a value > 32 (32 means Status LED6 is on), 
		// we need to reset the value of runningLight to 1 to start again
		// from the beginning...
		// Instead of "32" we could also write "0b100000".
		if(runningLight > 32)
			runningLight = 1; 	// reset runningLight to 1 (StatusLED1) 

		// If we want to see the running Light, we need to
		// add a delay here - otherwise our human eyes would not see
		// the moving light dot: 
		mSleep(100); // delay 100ms = 0.1s 

		// ---------------------------------------

	}
	// End of main loop
	// ---------------------------------------

	// ---------------------------------------
	// The Program will NEVER get here!
	// (at least if you don't perform a "break" in the main loop, which
	// you should not do usually!)

	return 0; 
}
Example #20
0
void DoDataProcess( void )
{
	uint8_t nrOfCharsReceived = getBufferLength();	
	// check if no data was received
	if (nrOfCharsReceived == 0) return;
	
	static char receiveBuffer[RECEIVE_BUFFER_SIZE];
	static int index = -1;
	
	static bool wrapped = false;

	while(getBufferLength() > 0)
	{
		char newchar = readChar();
		
		if(!wrapped)
		{
			if(newchar == '{')
			{
				wrapped = true;
			}
			continue;
		}
		
		if(newchar == '}')
		{					
			if(index > -1)
			{				
				//parse request
				REQUEST_STRUCT request = {0, 0};
				parseRequest(&request, receiveBuffer, (index+1));
				
				writeString_P("{cmd=0x");
				writeInteger(request.cmd, HEX);
				writeString_P(";val=0x");
				writeInteger(request.val, HEX);
				writeString_P("}\n");
				
				switch(request.cmd)
				{
					case CMD_MOVE_FORWARD:
					{		
						if(move_horizontal<=0)
						{
							move_horizontal = request.val;
							if (request.val > topSpeed)
							{
								topSpeed = request.val;
							}
						}
						else
						{
							move_horizontal = 0;
						}
						move_turning = 0;
						break;
					}
					case CMD_MOVE_BACKWARD:
					{		
						if(move_horizontal>=0)
						{
							move_horizontal = request.val;
						}
						else
						{
							move_horizontal = 0;
						}	
						move_turning = 0;
						break;
					}
					case CMD_MOVE_LEFT:
					{		
						if(move_turning<=0)
						{
							move_turning = 1;
						}
						else
						{
							move_turning = 0;
						}		
						move_horizontal = 0;
						break;
					}
					case CMD_MOVE_RIGHT:
					{		
						if(move_turning >= 0)
						{
							move_turning = -1;
						}
						else
						{
							move_turning = 0;
						}
						move_horizontal = 0;
						break;
					}
					case CMD_STOP_MOVING:
					{
						move_horizontal = 0;
						move_turning = 0;
						break;
					}
					case CMD_GET_FUELLVL:
					{
						writeString_P("{cmd=0x");
						writeInteger(request.cmd, HEX);
						writeString_P(";val=0x");
						writeInteger(get_BatteryLevelAsPercentage(), HEX);
						writeString_P("}\n");
						break;
					}
					
					case CMD_GET_SPEED:
					{
						writeString_P("{cmd=0x");
						writeInteger(request.cmd, HEX);
						writeString_P(";val=0x");
						writeInteger(topSpeed, HEX);
						writeString_P("}\n");
						break;
					}
					
					default: //stop
					{
						
					}
				}
				
				//
			}
			wrapped = false;
			index = -1;
			continue;
		}
		
		receiveBuffer[++index] = newchar;

		//- reserve the last character of the buffer for '\0' character
		//- check not to write outside array boundaries.	
		if (index > (RECEIVE_BUFFER_SIZE-2)) //loop from 0 to (RECEIVE_BUFFER_SIZE-)
		{
			index = -1;
			wrapped = false;
			//THROW 'exception'/Error
			continue;
		}
	}
}
Example #21
0
int main(void)
{
	initRP6Control(); // Always call this first! The Processor will not work
					  // correctly otherwise. 

	bars(2);
	writeString_P("\n\nRP6Control Selftest!\n\n"); 
	bars(2);
	setLEDs(0b1111);
	mSleep(50);
	initLCD(); 
	showScreenLCD("################", "################");

	mSleep(400);
	showScreenLCD("################", "################");
	showScreenLCD("RP6Control M32", "SELFTEST");

	mSleep(1000);
	
	uint8_t keynumber = 0;
	while(keynumber < 6)
	{
		uint8_t key = checkReleasedKeyEvent(); 
		if(key == keynumber)
		{
			keynumber++;
			showScreenLCD("PRESS BUTTON", "NUMBER ");
			writeIntegerLCD(keynumber,DEC);
			setLEDs(0b0000);
			writeString_P("### PRESS BUTTON NUMBER ");
			writeInteger(keynumber,DEC);
			writeString_P("!\n");
		}
	}
	
	
	showScreenLCD("Testing", "BEEPER & LEDS");
	mSleep(250);
	// Play a sound to indicate that our program starts:
	sound(50,50,100); setLEDs(0b0000);
	sound(80,50,100); setLEDs(0b0001);
	sound(100,50,100);setLEDs(0b0010);
	sound(120,50,100);setLEDs(0b0100);
	sound(140,50,100);setLEDs(0b1000);
	sound(160,50,100);setLEDs(0b1001);
	sound(180,50,100);setLEDs(0b1011);
	sound(200,50,100);setLEDs(0b1111);
	mSleep(400);
	setLEDs(0b0000);

	showScreenLCD("Testing", "EERPOM");
	
	test(1);
	writeString_P("\nEEPROM TEST\n");
	writeString_P("\nErasing 250 Bytes...\n");
	
	uint8_t cnt;
	for(cnt = 0; cnt < 250; cnt++)
	{
		SPI_EEPROM_writeByte(cnt, 0xFF);
		while(SPI_EEPROM_getStatus() & SPI_EEPROM_STAT_WIP);
	}

	writeString_P("...Done!\nWriting 250 Bytes to EEPROM:\n");
	for(cnt = 0; cnt < 250; cnt++)
	{
		writeIntegerLength(cnt, DEC, 3);
		SPI_EEPROM_writeByte(cnt, cnt);
		while(SPI_EEPROM_getStatus() & SPI_EEPROM_STAT_WIP);
		writeChar(',');
		if(cnt % 10 == 0) writeChar('\n');
	}
	
	mSleep(400);
	setLEDs(0b1111);
	writeString_P("\nReading and verifying:\n");
	
	for(cnt = 0; cnt < 250; cnt++)
	{
		uint8_t result = SPI_EEPROM_readByte(cnt);
		if(result != cnt)
		{
			writeString_P("\nEEPROM VERIFY ERROR!!!! EEPROM DAMAGED!!!\n");
			writeString_P("Data read: "); writeInteger(result,DEC);
			writeString_P(", should be: "); writeInteger(cnt,DEC); writeChar('\n');
			errors++;
		}
		else
			writeIntegerLength(result,DEC,3);
		writeChar(',');
		if(cnt % 10 == 0) writeChar('\n');
	}
	
	writeString_P("\nErasing 250 Bytes...\n");
	for(cnt = 0; cnt < 250; cnt++)
	{
		SPI_EEPROM_writeByte(cnt, 0xFF);
		while(SPI_EEPROM_getStatus() & SPI_EEPROM_STAT_WIP);
	}
	
	mSleep(400);
	setLEDs(0b0000);
	writeString_P("\nEEPROM TEST DONE!\n");
	writeString_P("\nI2C TWI TEST:\n");
	showScreenLCD("I2C TWI", "TEST");
	
	
	I2CTWI_initMaster(100);  
	I2CTWI_setTransmissionErrorHandler(I2C_transmissionError);
	
	uint8_t runningLight = 1;
	for(cnt = 0; cnt < 24; cnt++)
	{
		writeIntegerLength(cnt,DEC,3);
		writeChar(':');
		writeIntegerLength(runningLight,DEC,3);
		writeChar(',');
		writeChar(' ');

		I2CTWI_transmit3Bytes(I2C_RP6_BASE_ADR, 0, 3, runningLight);
		I2CTWI_transmitByte(I2C_RP6_BASE_ADR, 29);
		uint8_t result = I2CTWI_readByte(I2C_RP6_BASE_ADR);
		if(result != runningLight) 
		{
			writeString_P("\nTWI TEST ERROR!\n");
			errors++;
		}
		runningLight <<= 1; 
		if(runningLight > 32) 
			runningLight = 1;
	
		if((cnt+1) % 6 == 0) writeChar('\n');
		mSleep(100);
	}
	I2CTWI_transmit3Bytes(I2C_RP6_BASE_ADR, 0, 3, 0);
	
	writeString_P("\nTWI TEST DONE!\n");
	writeString_P("\nMicrophone Test\n");
	writeString_P("Hit the Microphone three times with your finger!\n");
	showScreenLCD("MIC TEST:", "");
	
	#define PREPARE 1
	#define WAIT 2
	
	uint8_t state = PREPARE;

	startStopwatch2();
	while(true)
	{
		static uint8_t peak_count = 3;
		if(state == PREPARE)
		{
			if(getStopwatch2() > 250)
			{
				setCursorPosLCD(1, 6); 
				writeIntegerLengthLCD( peak_count, DEC, 1);
				dischargePeakDetector();
				state = WAIT;
				setStopwatch2(0);
			}
		}
		else if(state == WAIT)
		{
			uint8_t key = checkReleasedKeyEvent(); 
			if(key)
			{
				break;
			}
			if(getStopwatch2() > 50)
			{
				uint16_t tmp = getMicrophonePeak();
				if(tmp > 4)
				{
					externalPort.LEDS = 0;
					uint16_t i;
					uint8_t j;
					for(i = 0, j = 2; i < tmp; i+= 40)
					{
						if(i < 40)
						{
							externalPort.LEDS++;
						}
						else
						{
							externalPort.LEDS <<=1;
							externalPort.LEDS++;
						}
					}
					outputExt();
					if(tmp > 120)
					{
						state = PREPARE;
						peak_count--;
					}
					if(peak_count == 0)
						break;
				}
				else
					setLEDs(0b0000);
				setStopwatch2(0);
			}
		}
	}

	writeString_P("\nMICROPHONE TEST DONE!\n");
	showScreenLCD("ALL TESTS", "DONE!");
	
	writeString_P("\n\n\n\n");
	bars(2);
	writeString_P("\n\nALL TESTS DONE!\n\n");
	
	if(errors)
	{
		bars(4);
		writeString_P("\nERROR ERROR ERROR ERROR ERROR ERROR ERROR\n");
		writeString_P("\nATTENTION: TESTS FINISHED WITH ERRORS!!!\n");
		writeString_P("PLEASE CHECK RP6-M32 ASSEMBLY!!!\n\n");
		bars(4);
		writeString_P("\n\n");
	}
	
	// Now we just show a running light...
	startStopwatch1();
	
	uint8_t runLEDs = 1; 
	uint8_t dir = 0;
	
	while(true) 
	{
		if(getStopwatch1() > 100) {
			setLEDs(runLEDs); 
			if(dir == 0)
				runLEDs <<= 1; 
			else
				runLEDs >>= 1;
			if(runLEDs > 7 ) 
				dir = 1;			
			else if (runLEDs < 2 ) 
				dir = 0;
			setStopwatch1(0);
		}
	}
Example #22
0
void ir_receiveBaseStation(void)
{
    uint8_t tijdelijk;
    writeString_P("aap!\n");
    while ((personX == 0xFF) || (personY == 0xFF) || (startX == 0xFF) || (startY == 0xFF)) {
        I2CTWI_transmitByte(I2C_RP6_BASE_ADR, 27);
        tijdelijk = I2CTWI_readByte(I2C_RP6_BASE_ADR);

        writeString_P("ADDR: ");
        writeInteger((int16_t) tijdelijk, DEC);

        I2CTWI_transmitByte(I2C_RP6_BASE_ADR, 28);
        tijdelijk = I2CTWI_readByte(I2C_RP6_BASE_ADR);

        writeString_P(" DATA: ");
        writeInteger((int16_t) tijdelijk, DEC);
        writeString_P("\n");

        mSleep(100);

        // implement device bit 0 - device bit - code

        // Oops! i did it again (van 44 naar 9)
        if (tijdelijk >= 48 && tijdelijk <= 56) {
            startY = tijdelijk - 48;
        } else if (tijdelijk >= 32 && tijdelijk <= 38) {
            startX = tijdelijk - 32;
        } else if (tijdelijk >= 16 && tijdelijk <= 24) {
            personY = tijdelijk - 16;
        } else if (tijdelijk <= 6) {
            personX = tijdelijk;
        }

        // for now, just put it on the screen
        clearLCD();

        setCursorPosLCD(0, 0);
        writeCharLCD('X');

        setCursorPosLCD(0, 2);
        writeIntegerLCD(startX, DEC);

        setCursorPosLCD(0, 10);
        writeCharLCD('Y');

        setCursorPosLCD(0, 12);
        writeIntegerLCD(startY, DEC);


        setCursorPosLCD(1, 0);
        writeCharLCD('X');

        setCursorPosLCD(1, 2);
        writeIntegerLCD(personX, DEC);

        setCursorPosLCD(1, 10);
        writeCharLCD('Y');

        setCursorPosLCD(1, 12);
        writeIntegerLCD(personY, DEC);
    }
}
Example #23
0
void done(void)
{
	writeString_P("Done!\n"); 
}
Example #24
0
int main(void)
{
	initRP6Control(); // Always call this first! The Processor will not work
					  // correctly otherwise. 

	initLCD(); 
	
	writeString_P("\n\nRP6Control I/O and ADC Example Program!\n"); 
	setLEDs(0b1111);

	showScreenLCD("################", "################");

	// Play a sound to indicate that our program starts:
	sound(100,40,64);
	sound(170,40,0);
	mSleep(400);
	setLEDs(0b0000);

	showScreenLCD("I/O and ADC", "Example Program");
	mSleep(1000);

	/*
		Here we will show how to set and read I/O pins. 
		
		You need to change this and add your own routines
		for the specific hardware you want to control!
		
		The 14 free I/O Pins are the following ones (definitions from RP6Control.h):
		
		ADC7 	(1 << PINA7)
		ADC6	(1 << PINA6)
		ADC5 	(1 << PINA5)
		ADC4 	(1 << PINA4)
		ADC3 	(1 << PINA3)
		ADC2 	(1 << PINA2)
		IO_PC7 	(1 << PINC7)
		IO_PC6 	(1 << PINC6)
		IO_PC5 	(1 << PINC5)
		IO_PC4 	(1 << PINC4)
		IO_PC3 	(1 << PINC3)
		IO_PC2 	(1 << PINC2)
		IO_PD6 	(1 << PIND6)
		IO_PD5 	(1 << PIND5)

		ADC2 - 7 are useable as I/Os or as Analog/Digital Converter Channels.
		IO_PC2 - 7 and IO_PD5 and IO_PD6 are only useable as I/Os.
		
		So you have free pins on PORTA, C and D.
		
		Please note the small difference in spelling ADC Channels and I/Os 
		(ADC_7 vs. ADC7)
	*/
	
	
	// When you want to use a port pin as output, you have to set the 
	// DDRx register bit belonging to this port to 1. 
	//
	// For example - if you want to use PORTC 7 as output, you can write:
	
	DDRC |= IO_PC7;  // PC7 is output
	
	// And then you can set the Port to high or low:
	
	
	PORTC |= IO_PC7;  // High
	writeString_P("\nPC7 is set to HIGH!\n\n");
	mSleep(1000);	  // wait 1s for example... 
	PORTC &= ~IO_PC7; // Low
	writeString_P("\nPC7 is set to LOW!\n\n");
	
	// When you want to use the Port as input to read its value,
	// you need to clear the DDRx register bit. 
	
	DDRC &= ~IO_PC6;  // PC6 is input
	
	PORTC |= IO_PC6;     // enable internal pullup resistor of PC6  OR ALTERNATIVELY:
	// PORTC &= ~IO_PC6  // disable pullup resistor of PC6
	// You need this when external sensors only pull the signal low
	// for example or if you disconnect the sensors or ... 
	
	// Now we want to output something depending on if this port pin is 
	// high or low:
	writeString_P("\nCheck PC6:");
	if(PINC & IO_PC6) // Check if PC6 is high
		writeString_P("\n\nPC6 is HIGH!\n\n");
	else
		writeString_P("\n\nPC6 is LOW!\n\n");
	
	
	// Hints for DDRx and PORTx Registers:
	// DDRx = 0 and PORTx = 0 ==> Input without internal Pullup
	// DDRx = 0 and PORTx = 1 ==> Input with internal Pullup
	// DDRx = 1 and PORTx = 0 ==> Output low
	// DDRx = 1 and PORTx = 1 ==> Output high
	// "=1" indicates that the appropriate bit is set.


	// To read the ADC channels, you can use the readADC() function. 
	// First you have to make the pins INPUTs, of course:
	DDRA &= ~ADC7;
	DDRA &= ~ADC2;
	

	// When you run this program with nothing connected
	// to the ADCs, you will most likely measure only junk
	// data - for example the ADC could show 210 or 623 or
	// anything else randomly. 
	
	// -------------------------------------------

	while(true) {
		writeString_P("\nADC7: ");
		uint16_t adc7 = readADC(ADC_7); // Read ADC Channel 7
		writeInteger(adc7, DEC);
		writeString(" | ADC2: ");
		uint16_t adc2 = readADC(ADC_2); // Read ADC Channel 2
		writeInteger(adc2, DEC);
		writeChar('\n');
		mSleep(500);
	}
	return 0;
}
Example #25
0
void askAQuestion(void)
{
	uint8_t bytesToReceive = 1;
	
	clearReceptionBuffer();
	switch(question)
	{
		case 0:
			writeString_P("What's your name? (Enter 8 characters please)\n"); 
			bytesToReceive = 8; 
		break;
		case 1:
			writeString_P("How old are you? (Enter 2 characters please)\n"); 
			bytesToReceive = 2;
		break;
		case 2: 
			writeString_P("Do you want to see some Text output? (\"y\" or \"n\")\n"); 
		break;
		case 3: 
			writeString_P("Do you want to see blinking LEDs and hear the beeper sound? (\"y\" or \"n\")\n"); 
		break;
		case 4: 
			writeString_P("Do you want to do all this again? (\"y\" or \"n\")\n"); 
		break;
	}

	for(size_t i=0; i<100 && getBufferLength() < bytesToReceive; ++i)
		;	
	char receiveBuffer[bytesToReceive];
	readChars(receiveBuffer, bytesToReceive);	

	switch(question)
	{
		case 0: 
			writeString_P("Hello \"");
			writeStringLength(&receiveBuffer[0],bytesToReceive,0);
			writeString_P("\" !\n");
		break;
		case 1: 
			writeString_P("So your age is: \""); 
			writeStringLength(&receiveBuffer[0],bytesToReceive,0);
			writeString_P("\" ! Guess what? Nobody cares... ;-)\n");
		break;
		case 2:
			if(receiveBuffer[0] == 'y') 
			{
				writeString_P("Here we go!\n");
				outputTextStuff();
				writeString_P("\n\nThat's it!\n\n"); 
			}
			else
				writeString_P("OK then... let's move on!\n"); 
		break;
		case 3:
			if(receiveBuffer[0] == 'y')
			{
				writeString_P("Now you get a led and beeper show!\n");
				uint8_t i = 0;
				for(;i < 10; i++)
					Leds_Beeper();
				writeString_P("Oh ... it's over!\n");
			}
			else
				writeString_P("Well, if you don't want that... :*( \n"); 
		break;
		case 4:
			if(receiveBuffer[0] == 'y')
			{
				writeString_P("Great! Here we go again...\n"); 
				question = -1;
			}
			else
			{
				writeString_P("OK good bye! I will wait \n");
				writeString_P("until someone resets me!\n"); 
				question = -2;
			}
		break;
	}
	
	question++;
}
int main(void)
{
	initRobotBase();

	setLEDs(0b111111);
	mSleep(500);
	setLEDs(0b000000);

	writeString_P("\nJust a simple counter program\n\n");
	
	uint16_t counter = 0;

	while(true)
	{
		timer = 0; 
		if(counter < 100) 
		{
			writeString_P("Counter: ");
			writeInteger(counter, BIN);
			writeString_P("(BIN) | ");
			writeInteger(counter, OCT);
			writeString_P("(OCT) | ");
			writeInteger(counter, DEC);
			writeString_P("(DEC) | ");
			writeInteger(counter, HEX);
			writeString_P("(HEX) ");
		}
		else
		{
			writeString_P("Counter L: ");
			writeIntegerLength(counter, BIN, 16);  
			writeString_P("(BIN) | ");
			writeIntegerLength(counter, OCT, 6);
			writeString_P("(OCT) | ");
			writeIntegerLength(counter, DEC, 6);
			writeString_P("(DEC) | ");
			writeIntegerLength(counter, HEX, 4);
			writeString_P("(HEX) ");
		}
		
		writeChar(' ');
		writeInteger(timer,DEC); 
		writeString(" *100us");
		writeChar('\n');
		
		counter++;  
		mSleep(100);
	}
	return 0;
}