コード例 #1
0
ファイル: main.c プロジェクト: nllan001/journal-project
/* calibrates the sensor that is passed in */
unsigned short calibrate(unsigned char resistor) {
	Set_A2D_Pin(resistor);
	for(int i = 0; i < 100; ++i);
	unsigned short avg = 0;
	for(int i = 0; i < 10; ++i) avg += ADC;
	return avg / 10;
}
コード例 #2
0
ファイル: main.c プロジェクト: nllan001/journal-project
/* check the value of a specific resistor like at 0x02 (pin 2)
   and return whether it senses a shadow or not */ 
bool checkPhotoValue(unsigned char resistor) {
	unsigned short photoValue;
	switch(resistor) {
		case 0x02:
			photoValue = photoValueL;
			break;
		case 0x00:
			photoValue = photoValueU;
			break;
		case 0x04:
			photoValue = photoValueR;
			break;
		case 0x01:
			photoValue = photoValueD;
			break;
		case 0x05:
			photoValue = photoValueU2;
			break;
		case 0x06:
			photoValue = photoValueD2;
			break;
		default:
			return false;
			break;
	}
	Set_A2D_Pin(resistor);
	for(int i = 0; i < 100; ++i);
	unsigned short input = ADC;
	if(input < photoValue) {
		return true;
	} else {
		return false;
	}
}
コード例 #3
0
int User_Tick(int state) {
	
    // === Local Variables ===
	unsigned short x_joystick = 512;
	unsigned short y_joystick = 512;
	unsigned char tmpA = PINA;
	unsigned char pina2 = ~tmpA & 0x04;
	
    // === Transitions ===
    switch (state) {
		case -1:
			state = set_x;
			break;
   		case set_x:
		   if (isgameover) { state = gameover; }   		   
		   else { state = read_x; }
		   break;
		case read_x:
			if (isgameover) { state = gameover; }   		
			else { state = set_y; }
			break;
		case set_y:
			if (isgameover) { state = gameover; }   		
			else { state = read_y; }
			break;
		case read_y:
		    if (isgameover) { state = gameover; }   		
			else { state = set_x; }
			break;
		case gameover:
			if (isreset) { state = -1; }
			else { state = gameover; }
		default:
			state = set_x;
			break;
    }
    
    // === Actions ===
    switch (state) {
		case set_x:
			Set_A2D_Pin(0);
			break;
		case read_x:
			x_joystick = ADC;
			break;
		case set_y:
			Set_A2D_Pin(1);
			break;
		case read_y:
			y_joystick = ADC;
			break;
		case gameover:
			if (pina2) { isreset = 1; }
			break;
		default:
			break;  
    }
	
	if (y_joystick < 312) //up
	{
		if (user_row[0] != 0x01)
		{
			for (unsigned i=0; i<4; i++)
			{
				user_row[i] = user_row[i] >> 1;
			}
		}
	}
	else if (y_joystick > 712) //down