Fix serial comms
This commit is contained in:
		
							parent
							
								
									6f5f32b1ca
								
							
						
					
					
						commit
						8fa0623d74
					
				
					 1 changed files with 27 additions and 28 deletions
				
			
		|  | @ -1,9 +1,3 @@ | |||
| /* Funduino Joystick Shield Example
 | ||||
| 
 | ||||
| This program simply captures all of the inputs of the Funduino Joystick Shield buttons and | ||||
| joystick every second and displays them in the Serial Monitor Window.   | ||||
| The Arduino pins below are defined by the shield and cannot be changed. | ||||
| */ | ||||
| int const UP_BTN = 2; | ||||
| int const DOWN_BTN = 4; | ||||
| int const LEFT_BTN = 5; | ||||
|  | @ -14,29 +8,34 @@ int const JOYSTICK_BTN = 8; | |||
| int const JOYSTICK_AXIS_X = A0; | ||||
| int const JOYSTICK_AXIS_Y = A1; | ||||
| int buttons[] = {UP_BTN, DOWN_BTN, LEFT_BTN, RIGHT_BTN, E_BTN, F_BTN, JOYSTICK_BTN}; | ||||
| //===============================================================================
 | ||||
| //  Initialization
 | ||||
| //===============================================================================
 | ||||
| void setup() { | ||||
|   //Set all button pins as inputs with internal pullup resistors enabled.
 | ||||
|   for (int i; i < 7; i++)  pinMode(buttons[i], INPUT_PULLUP); | ||||
|   Serial.begin(9600); | ||||
| } | ||||
| //===============================================================================
 | ||||
| //  Main
 | ||||
| //===============================================================================
 | ||||
| void loop() { | ||||
|   // Check each button input and print the status to the Serial Monitor Window
 | ||||
|   Serial.print("UP="),Serial.print(digitalRead(UP_BTN)); | ||||
|   Serial.print("\tDOWN="),Serial.print(digitalRead(DOWN_BTN)); | ||||
|   Serial.print("\tLEFT="),Serial.print(digitalRead(LEFT_BTN)); | ||||
|   Serial.print("\tRIGHT="),Serial.print(digitalRead(RIGHT_BTN)); | ||||
|   Serial.print("\tE="),Serial.print(digitalRead(E_BTN)); | ||||
|   Serial.print("\tF="),Serial.print(digitalRead(F_BTN)); | ||||
|   Serial.print("\tJOYSTICK BTN="),Serial.print(digitalRead(JOYSTICK_BTN)); | ||||
| int line = 1; | ||||
| 
 | ||||
|   // Print the full X/Y joystick values (0-1023)
 | ||||
|   Serial.print("\tX="),Serial.print(analogRead(JOYSTICK_AXIS_X)); | ||||
|   Serial.print("\tY="),Serial.println(analogRead(JOYSTICK_AXIS_Y));  | ||||
|   delay(250); | ||||
|  } | ||||
| void setup() { | ||||
|   Serial.begin(9600); | ||||
|   Serial.println("Serial Started"); | ||||
|   for (int i=0; i < 7; i++)  pinMode(buttons[i], INPUT_PULLUP); | ||||
|   Serial.println("Finished pin setup"); | ||||
|   delay(2000); | ||||
| } | ||||
| 
 | ||||
| void loop() { | ||||
|   Serial.print(line); | ||||
|   Serial.print(". Yeet!\n"); | ||||
|    | ||||
|   Serial.print("UP="),Serial.println(digitalRead(UP_BTN)); | ||||
|   Serial.print("DOWN="),Serial.println(digitalRead(DOWN_BTN)); | ||||
|   Serial.print("LEFT="),Serial.println(digitalRead(LEFT_BTN)); | ||||
|   Serial.print("RIGHT="),Serial.println(digitalRead(RIGHT_BTN)); | ||||
|   Serial.print("E="),Serial.println(digitalRead(E_BTN)); | ||||
|   Serial.print("F="),Serial.println(digitalRead(F_BTN)); | ||||
|   Serial.print("JOYSTICK BTN="),Serial.println(digitalRead(JOYSTICK_BTN)); | ||||
| 
 | ||||
|   // Joystick range is from 0 to 653 +- 1
 | ||||
|   // Center is about 323 +- 2. A deadzone of 10 or 20 should be safe.
 | ||||
|   Serial.print("X: "); | ||||
|   Serial.println(analogRead(JOYSTICK_AXIS_X)); | ||||
|   Serial.print("Y: "); | ||||
|   Serial.println(analogRead(JOYSTICK_AXIS_Y));  | ||||
|   line++; | ||||
|   delay(150); | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue