Exemple #1
0
//Main function
int main() {

    //Create a variable to hold the bit pattern
    unsigned int u;

    //Flash LED's to indicate the code is running
    binaryOutput = 7;
    wait(0.5);
    binaryOutput = 0;

    while(1) {
        
        u = 7;             //Set initial value 111
        binaryOutput = u;  //Show binary on LED's
        waitForButtonPress(); //Call function      
  
        //Use & to reset bit 1 
        u = u & 5;          //AND with binary 101
        binaryOutput = u;   
        waitForButtonPress();   
                               
        //Modify u with & to reset bit 2 to a 0
        u = u & 3;  //AND with 011
        binaryOutput = u;   
        waitForButtonPress();                          


        //Modify u with & to reset bit 0 to a 0
        u = u & 6;  //AND with 110
        binaryOutput = u;   
        waitForButtonPress();   
        
    } //end while(1)
} //end main
Exemple #2
0
void setup() {
    pinMode(BOARD_BUTTON_PIN, INPUT);

    comm.begin(9600);
    comm.println("*** Beginning BKP test");

    comm.println("Init...");
    bkp_init();
    comm.println("Done.");

    print_bkp_contents();
    write_to_bkp(10);
    print_bkp_contents();

    comm.println("Enabling backup writes.");
    bkp_enable_writes();
    write_to_bkp(20);
    print_bkp_contents();

    comm.println("Disabling backup writes.");
    bkp_disable_writes();
    write_to_bkp(30);
    print_bkp_contents();

    comm.println("Done testing backup registers; press button to enable "
                    "independent watchdog (in order to cause a reset).");
    waitForButtonPress(0);
    iwdg_init(IWDG_PRE_4, 1);
    comm.println();
}
Exemple #3
0
//Main function
int main() {

    //Create a variable to hold the bit pattern
    unsigned int u;

    //Flash LED's to indicate the code is running
    binaryOutput = 7;
    wait(0.5);
    binaryOutput = 0;

    while(1) {
        
        u = 0;             //Set initial value 0
        binaryOutput = u;  //Show binary on LED's
        waitForButtonPress(); //Call function      
  
        //Use & to toggle bit 0 
        u = u ^ 1;          //XOR with binary 001
        binaryOutput = u;   
        waitForButtonPress();   
                               
        //Toggle bit 1
        //WRITE CODE HERE
        binaryOutput = u;   
        waitForButtonPress();                          


        //Toggle bit 2
        //WRITE CODE HERE
        binaryOutput = u;   
        waitForButtonPress();   
        
        //Toggle bits 0 and 2
        //WRITE CODE HERE
        binaryOutput = u;   
        waitForButtonPress();  
        
        //Toggle all bits
        //WRITE CODE HERE
        binaryOutput = u;   
        waitForButtonPress();
        
        //Toggle all bits
        //WRITE CODE HERE
        binaryOutput = u;   
        waitForButtonPress();               
        
    } //end while(1)
} //end main
task LCDSelect() {
	if (showVersion) {
		clearLCD();
		displayLCDCenteredString(0,"LCD Select v2.0-f"); //briefly display version for debug purposes
		wait1Msec(750);
	}
	showVersion = false; //don't show the version again if autonSelection is ever reset


	//Q1: Which side?
	showOnLCD("Which side?","Left  Right  Sk.");
	waitForPress();
	int q1Response = nLCDButtons;
	waitForRelease();
	int q2Page = 1; //1 - Big/Small choices shown, 2 - Cube/Fence choices shown, 3 - Nothing choice shown
	int q2Response = 0;
	int q2PlayChosen = 0;

	if (q1Response != 4) {

		while (q2PlayChosen == 0) {

			if (q2Page == 1) {
				if (LCD_CUBE && LCD_STARS) {
					showOnLCD("Choose play: 1/2","Cube   Star   >>");
				} else if (LCD_CUBE && !LCD_STARS) {
				  showOnLCD("Choose play:","Cube          >>");
				} else if (!LCD_CUBE && LCD_STARS) {
				  showOnLCD("Choose play:","       Star   >>");
				} else {
					showOnLCD("Press any btn","");
				}

				wait1Msec(250); //short delay to prevent button press from triggering multiple times
				waitForPress();
				q2Response = nLCDButtons;
				if (q2Response == 4) {
					q2Page = 3;
				} else if (q2Response == 1) {
					q2PlayChosen = 1;
				} else if (q2Response == 2) {
					q2PlayChosen = 2;
				}
				waitForRelease();
				if (q2Response == 1 ||q2Response == 2) {
					break;
				}

			}/* else if (q2Page == 2) {
				showOnLCD("Choose play: 2/3","Cube   Fence  >>");
				wait1Msec(250);
			  waitForPress();
				q2Response = nLCDButtons;
				if (q2Response == 4) {
					q2Page = 3;
				} else if (q2Response == 1) {
					q2PlayChosen = 3;
				} else if (q2Response == 2) {
					q2PlayChosen = 4;
				}
				waitForRelease();
				if (q2Response == 1 ||q2Response == 2) {
					break;
				}
			} */else if (q2Page == 3) {
				showOnLCD("Choose play: 2/2","Nothing       >>");
				wait1Msec(250);
			  waitForPress();
				q2Response = nLCDButtons;
				if (q2Response == 4) {
					q2Page = 1;
				} else if (q2Response == 1) {
					q2PlayChosen = 4;
				}
				waitForRelease();
				if (q2Response == 1 ||q2Response == 2) {
					break;
				}
			} //end else if
		} //end while
	} //end if


	if (q1Response == 4) {
		AUTON_PLAY = 3;
		playConfirmName = "Prog. skills";
	} else {
		if (q1Response == 1) {
			AUTON_SIDE = LEFT;
		} else { //q1Response == 2
			AUTON_SIDE = RIGHT;
		}
		switch (q2PlayChosen) {
			case 1:
				AUTON_PLAY = 1;
				playConfirmName = "Cube";
				break;
			case 2:
				AUTON_PLAY = 2;
				playConfirmName = "Back stars";
				break;
			//case 3 would be programming skills, which is handled above
			case 4:
				AUTON_PLAY = 4;
				playConfirmName = "NOTHING";
				break;
		}
	}

	startTask(confirmChoice);
	wait1Msec(250);
	int confirmResult = waitForButtonPress();
	stopTask(confirmChoice);
	if (confirmResult == 2) {
		if (AUTON_PLAY == 5) {
			showOnLCD("NOTHING","No auton!");
		} else {
			showOnLCD(playConfirmName,"will run!");
		}
	} else {
		startTask(restartAutonSelection);
	}



} //end task
Exemple #5
0
/*MAIN*/
int main()
{
	//Declarations
	int i, j;
	int targets;
	int center, error, most_blob;
	int num_balls = 5;
	int dist, prev;
	int n = 0;

	//Set up GPIO
	gpio_export(POWER_LED_PIN); 
	gpio_set_dir(POWER_LED_PIN, OUTPUT_PIN);
	gpio_export(CAMERA_LED_PIN);
	gpio_set_dir(CAMERA_LED_PIN, OUTPUT_PIN);
	gpio_export(BUTTON_PIN);
	gpio_set_dir(BUTTON_PIN, INPUT_PIN);
	gpio_export(RELOAD_LED_PIN);
	gpio_set_dir(RELOAD_LED_PIN, OUTPUT_PIN);
	gpio_export(ARDUINO_PIN);
	gpio_set_dir(ARDUINO_PIN, OUTPUT_PIN);
	gpio_set_value(ARDUINO_PIN, LOW);

	//Set up PWM
	initPWM();
	usleep(microsecondsToMilliseconds(500));
	//Dropper
	setPeriod(DROPPER_MOTOR_INDEX, PWM_PERIOD);
	setDuty(DROPPER_MOTOR_INDEX, percentageToDuty(DROPPER_DOWN_POSITION));
	setRun(DROPPER_MOTOR_INDEX, 1);
	//Grabber
	setPeriod(GRABBER_MOTOR_INDEX, PWM_PERIOD);
	setDuty(GRABBER_MOTOR_INDEX, GRABBER_UP_POSITION);
	setRun(GRABBER_MOTOR_INDEX, 1);
	//Right wheel
	setPeriod(RIGHT_WHEEL_INDEX, PWM_PERIOD);
	setDuty(RIGHT_WHEEL_INDEX, NEUTRAL_DUTY);
	setRun(RIGHT_WHEEL_INDEX, 0);
	//Left wheel
	setPeriod(LEFT_WHEEL_INDEX, PWM_PERIOD);
	setDuty(LEFT_WHEEL_INDEX, NEUTRAL_DUTY);
	setRun(LEFT_WHEEL_INDEX, 0);
	//Roller
	setRun(ROLLER_MOTOR_INDEX, 0);
	setPeriod(ROLLER_MOTOR_INDEX, PWM_PERIOD);
	setDuty(ROLLER_MOTOR_INDEX, PWM_PERIOD*ROLLER_SPEED);

	//Set up serial
	serial* arduinoSerial;
	if (serial_open(&arduinoSerial, ARDUINO_SERIAL_PORT, ARDUINO_BAUD_RATE) == 0){
		printf("Opened Ardunio serial port sucessfully\n");
	}
	else{
		printf("Failed to open Arduino serial port\n");
	}
	
	/*for(i = 0; i < 50; i++)
	{
		dist = getDistance(arduinoSerial);
		printf("Instensity: %d\n", dist);
		usleep(microsecondsToMilliseconds(100));
	}
	usleep(microsecondsToMilliseconds(5000));*/
	
	//Turn on power LED
	gpio_set_value(POWER_LED_PIN, HIGH);
	printf("Systems are GO for launch!\n");

	waitForButtonPress();
	getDistance(arduinoSerial);

	//Move to center of the board
	goForward();
	usleep(microsecondsToMilliseconds(1800));
	stopWheels();

	//Aim at right target
	rotate(180);
	if(aimAtSideMostTarget(1))
	{
		for (; num_balls > 3; num_balls--)
		{
			fireGolfBall();
		}
	}
	//Move toward left target
	rotate(-550);
	goForward();
	usleep(microsecondsToMilliseconds(2200));
	stopWheels();
	//Aim at left target
	rotate(300);
	if(aimAtSideMostTarget(0))
	{
		for (; num_balls > 1; num_balls--)
		{
			fireGolfBall();
		}
	}
	//Aim at middle target
	rotate(260);
	aimAtBiggestTarget();
	for(; num_balls > 0; num_balls--)
	{
		fireGolfBall();
	}

	//Move to sideline for reload
	rotate(-600);
	goForward();
	buffer_clear(arduinoSerial);
	do
	{
		prev = dist;
		dist = getDistance(arduinoSerial);
		//printf("%d, ", dist);
		usleep(microsecondsToMilliseconds(9));
	}
	while (dist < DISTANCE_TO_WALL || dist == 0 || prev - dist > 5);
	stopWheels();
	rotate(1100);
	//Turn on reload LED
	gpio_set_value(RELOAD_LED_PIN, HIGH);
	usleep(microsecondsToMilliseconds(3000));
	gpio_set_value(RELOAD_LED_PIN, LOW);

	while (n < 3) //big while loop thing!
	{

	//start from left
	num_balls = 5;
	goForward();
	usleep(microsecondsToMilliseconds(1200));
	stopWheels();
	rotate(-420);
	goForward();
	usleep(microsecondsToMilliseconds(590));
	stopWheels();

	//Aim at left target
	if(aimAtSideMostTarget(0))
	{
		for(; num_balls > 3; num_balls--)
		{
			fireGolfBall();
		}
	}

	//Aim at middle target
	rotate(420);
	goForward();
	usleep(microsecondsToMilliseconds(600));
	stopWheels();
	rotate(-150);
	aimAtBiggestTarget();
	for(; num_balls > 2; num_balls--)
	{
		fireGolfBall();
	}

	//Aim at right target
	rotate(400);
	goForward();
	usleep(microsecondsToMilliseconds(2700));
	stopWheels();
	rotate(-370);
	if(aimAtSideMostTarget(1))
	{
		for(; num_balls > 0; num_balls--)
		{
			fireGolfBall();
		}
	}

	//Move to sideline for reload
	rotate(320);
	//usleep(microsecondsToMilliseconds(50));
	goForward();

	buffer_clear(arduinoSerial);
	dist = 0;
	do
	{
		prev = dist;
		dist = getDistance(arduinoSerial);
		//printf("And another thing....\n");
		//printf("%d!!! \n", dist);
		usleep(microsecondsToMilliseconds(10));
	}while (dist < DISTANCE_TO_WALL || dist == 0 || prev - dist > 5);

	stopWheels();
	rotate(-900);
	gpio_set_value(RELOAD_LED_PIN, HIGH);
	usleep(microsecondsToMilliseconds(3000));
	gpio_set_value(RELOAD_LED_PIN, LOW);

	//start from right
	num_balls = 5;
	goForward();
	usleep(microsecondsToMilliseconds(1350));
	stopWheels();
	rotate(570);

	//Aim at right target
	if(aimAtSideMostTarget(1))
	{
		for(; num_balls > 3; num_balls--)
		{
			fireGolfBall();
		}
	}

	//Aim at middle target
	rotate(-500);
	goForward();
	usleep(microsecondsToMilliseconds(4500));
	stopWheels();
	rotate(650);
	aimAtBiggestTarget();
	for(; num_balls > 2; num_balls--)
	{
		fireGolfBall();
	}

	//Aim at left target
	rotate(-200);
	if(aimAtSideMostTarget(0))
	{
		for(; num_balls > 0; num_balls--)
		{
			fireGolfBall();
		}
	}

	//Move to sideline for reload
	rotate(-400);
	goForward();
	buffer_clear(arduinoSerial);
	do
	{
		prev = dist;
		dist = getDistance(arduinoSerial);
		usleep(microsecondsToMilliseconds(9));
	}
	while(dist < DISTANCE_TO_WALL || dist == 0 || prev - dist > 5);
	stopWheels();
	rotate(1000);
	gpio_set_value(RELOAD_LED_PIN, HIGH);
	usleep(microsecondsToMilliseconds(3000));
	gpio_set_value(RELOAD_LED_PIN, LOW);

	} //end of while loop


	//Turn off gpio power
	gpio_set_value(POWER_LED_PIN, LOW);
	gpio_set_value(RELOAD_LED_PIN, LOW);
	gpio_set_value(ARDUINO_PIN, LOW);
	
	//Turn off motors
	setRun(GRABBER_MOTOR_INDEX, 0);
	setRun(DROPPER_MOTOR_INDEX, 0);
	setRun(ROLLER_MOTOR_INDEX, 0);
	setRun(RIGHT_WHEEL_INDEX, 0);
	setRun(LEFT_WHEEL_INDEX, 0);

	//Remove GPIO files
	//gpio_unexport(PING_PIN);

  	return 0;
}
Exemple #6
0
task main()
{
		struct Account accountList[NUMACCOUNTS];
		initAccounts(accountList, NUMACCOUNTS);

		string account;
		string cardnum;
		string pin;
		int accountindex;
		bool pinCorrect;

		while (getBatteryCurrent() > 0.02)
		{
			/*
			displayString(0,"Swipe card to Begin");
			do
			{
				cardnum = getCardSwipe();
				accountindex = doesExist(cardnum, accountList);
				displayString(0,"ERROR Card Not Found!!");
			}while (accountindex == -1);
			eraseDisplay();
			do
			{
				pinCorrect = checkPin(accountList);
				displayString(0,"ERROR Incorrect PIN");
			}while (pinCorrect == false);
			wait1Msec(100);
			eraseDisplay();
			wait1Msec(500);*/

			//Selection Menu
			while (getButtonPress(buttonEnter) != 1)
			{
					eraseDisplay();
					displayString(1,"Press center button to close transaction");
					displayString(2,"<----                   ---->");
					displayString(3,"Deposit             Withdraw");
					displayString(4,"     Balance: %f", accountList[accountindex].balance);

					waitForButtonPress();

			    if (getButtonPress(buttonLeft) == 1)
			    {
			    		int amount = doDeposit();
			        accountList[accountindex].balance += amount;
							eraseDisplay();
			        displayString(0,"%d", amount);
			    }
			    else if (getButtonPress(buttonRight) ==1)
			    {
			            int amount = doWithdraw(accountList[accountindex]);
			            if (amount != -1)
			            {
			            	accountList[accountindex].balance -= amount;
			            }
			    }
		  }

	    wait1Msec(5000);


		}
}