Hi,
The result from the joystick aren't the same with the arduino IDE program code and the B4R IDE program code.
josystick position normal:
B4R
Arduino
Stick move to the left
B4R
A
Arduino
Same strange behavior with the other position
Thanks for your help.
The code are:
B4R
Arduino
The result from the joystick aren't the same with the arduino IDE program code and the B4R IDE program code.
josystick position normal:
B4R
X = 3
Y = 551
Button = 1
X = 3
Y = 550
Button = 1
X = 3
Y = 551
Button = 1
Arduino
x: 525 Y: 511 Z: 1
x: 525 Y: 511 Z: 1
x: 524 Y: 512 Z: 1
Stick move to the left
B4R
A
X = 546
Y = 349
Button = 1
X = 545
Y = 349
Button = 1
Arduino
x: 1023 Y: 512 Z: 1
x: 1023 Y: 512 Z: 1
Same strange behavior with the other position
Thanks for your help.
The code are:
B4R
B4X:
'WIRE LEGEND for KY-023
'GND = GND
'+5V = 5V
'VRy = A0
'VRx = A1
'SW = D2
'*************************
'*** BOARD TYPE ***
'*** Arduino All ***
'*************************
Sub Process_Globals
'These global variables will be declared once when the application starts.
'Public variables can be accessed from all modules.
Public Serial1 As Serial
Private Switch, VRx, VRy As Pin
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
Switch.Initialize(2, Switch.MODE_INPUT_PULLUP)
VRx.Initialize(VRx.A0, VRx.AnalogRead)
VRy.Initialize(VRy.A1, VRy.AnalogRead)
AddLooper("ReadJoystick")
End Sub
Sub ReadJoystick
Log("X = ", VRx.AnalogRead)
Log("Y = ", VRy.AnalogRead)
Log("Button = ", Switch.DigitalRead)
Delay(250)
End Sub
Arduino
B4X:
const int sw_pin = 4;
const int x_pin = 0;
const int y_pin = 1;
void setup() {
pinMode(sw_pin, INPUT);
digitalWrite(sw_pin, HIGH);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.print("x: ");
Serial.print(analogRead(x_pin));
Serial.print(" Y: ");
Serial.print(analogRead(y_pin));
Serial.print(" Z: ");
Serial.println(digitalRead(sw_pin));
delay(250);
}