Appearance
Joystick
Overview
The joystick in the AlphaBot2 provides an intuitive way to interact with the robot, making it great for beginners learning about analog inputs and motor control. With some programming, you can extend its functionality for more advanced projects.
Key Feature
- Movements In Joystick
- Two analog axes (X and Y) – Measures movement in horizontal and vertical directions.
- A push-button (Z-axis) – Can be pressed down for an additional input.
- Analog Inputs (X & Y)
- Moving it forward/backward or left/right changes the voltage, which is read by the microcontroller.
- When centered, it outputs ~2.5V (or a mid-range ADC value).
- Digital Input (Button Press)
- The joystick can be pressed down, acting like a button, which is useful for triggering actions (e.g., changing modes)..
Working
- Joystick Module
- Connected to the PCF8574 I/O expander (I2C address 0x20).
- Uses 5 bits (bits 0-4) to represent directions (Up, Down, Left, Right, Center press).
- The remaining 3 bits (bits 5-7) are likely used for other functions (e.g., buzzer).
- PCF8574Read()
- Reads 1 byte from the PCF8574 (joystick state).
- Example: If "Up" is pressed, it returns 0xFE (binary 11111110).
- PCF8574Write(data)
- Writes a byte to the PCF8574 (used to reset/update I/O states).
- Reading Joystick State (PCF8574Read() | 0xE0)
- The | 0xE0 operation ensures only the joystick bits (0-4) are checked.
Joystick Logic
Direction | HEX VALUE | BINARY |
---|---|---|
Up | 0xFE | 11111110 (Bit 0 = 0) |
Right | 0xFD | 11111101 (Bit 1 = 0) |
Left | 0xFB | 11111011 (Bit 2 = 0) |
Down | 0xF7 | 11110111 (Bit 3 = 0) |
Center | 0xEF | 11101111 (Bit 4 = 0) |
No Press | 0xFF | 11111111 (All bits high) |