Hi,
I'm facing a strange behaviours. The following code works as expected:
#include <Arduino.h>
//Joystick 0
#define Joystick0 0
const u_short js0XPin = 0;
const u_short js0YPin = 1;
const u_short js0ZPin = 2;
void setup() {
Serial.begin(115200);
Serial.println("Launching setup");
// pinMode(js0XPin, INPUT);
// pinMode(js0YPin, INPUT);
pinMode(js0ZPin, INPUT_PULLUP);
Serial.println("Jumping to loop");
}
void loop() {
// put your main code here, to run repeatedly:
int js0XValue = analogRead(js0XPin);
int js0YValue = analogRead(js0YPin);
int js0ZValue = digitalRead(js0ZPin);
Serial.print("Joystick 0 - X: ");
Serial.print(js0XValue);
Serial.print(" Y: ");
Serial.print(js0YValue);
Serial.print(" Z: ");
Serial.println(js0ZValue);
delay(1000);
}
The monitor shows the read values every second
\--- Terminal on /dev/cu.usbmodem1101 | 115200 8-N-1
--- Available filters and text transformations: debug, default, direct, hexlify, log2file, nocontrol, printable, send_on_enter, time
--- More details at https://bit.ly/pio-monitor-filters
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H
Launching setup
Jumping to loop
Joystick 0 - X: 786 Y: 768 Z: 1
Joystick 0 - X: 791 Y: 775 Z: 1
Joystick 0 - X: 791 Y: 775 Z: 1
Joystick 0 - X: 792 Y: 775 Z: 1
If I just uncomment the lines where the analog pins are defined as input:
pinMode(js0XPin, INPUT);
pinMode(js0YPin, INPUT);
The monitor doesn't show anything but a couple of garbage characters:
--- Terminal on /dev/cu.usbmodem1101 | 115200 8-N-1
--- Available filters and text transformations: debug, default, direct, hexlify, log2file, nocontrol, printable, send_on_enter, time
--- More details at https://bit.ly/pio-monitor-filters
--- Quit: Ctrl+C | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H
�