Пример #1
0
//------------------------------------------------------------------------------
// An adaptation of the loop in main() in the original Babuino code.
// This is intended to be called from within the Arduino loop() function.
//------------------------------------------------------------------------------
void 
Babuino::loop()
{
	debounce();
	
	switch (_states.getMachineState())
		{
		case READY:
			if (serialAvailable() > 0)
			{
				_states.setMachineState(COMM);
			}
			else if (_states.getRunRequest() == RUNNING)
			{
				_states.setMachineState(RUN);
			}
			break;

		case COMM:
			doComm();
			_states.setMachineState(READY);
			break;

		case RUN:
			_regs.pc.set(_storage.getStartAddress());
			initStack(_stack);
			_states.setMachineState(RUN);
			code_exec();
			_motors.off();
			_states.setMachineState(READY);
			break;
		}
}
Пример #2
0
/* getComm - get message from serial ----------------------------------------*/
void getComm()
{
	// read all incoming bytes
	while(is_read_uart1())
	{
		char byte = read_uart1();
		// if one line is complete
		if (byte == '\n')
		{
			doComm();
			l = 0;
		}
		// don't use \r
		else// if (byte != '\r') // use \r as limitter
		{
			line[l++] = byte;
		}
		
	}
}