Week 6, Input & Output¶
What is Input device?¶
A piece of equipment used to provide data and control signals to an information processing system, such as a computer or information appliance.
Examples of input devices:¶
- keyboards
- mouse
- scanners
- cameras
- joysticks
- and microphones
What is Output device?¶
A piece of computer equipment that receives data from one source and converts it into another form.
Examples of output devices:¶
- monitors
- printers
- speakers
- headphones
- projectors
- GPS devices
Individual Task 1 (dealing with a joystick)¶
Each student were asked to take an input device and try to print its data on screen while using it. for me, I had to deal with joystick, the idea was just to print its data whenever make a move on it as an input action.
My code:¶
// Pin assignments
const int joystickXPin = A0; // Analog input pin for X-axis
const int joystickYPin = A1; // Analog input pin for Y-axis
const int buttonPin = 2; // Digital input pin for button
void setup() {
// Initialize serial communication
Serial.begin(9600);
// Set button pin as input with internal pull-up resistor
pinMode(buttonPin, INPUT_PULLUP);
}
void loop() {
// Read analog values from X and Y axis
int xValue = analogRead(joystickXPin);
int yValue = analogRead(joystickYPin);
// Read button state
int buttonState = digitalRead(buttonPin);
// Print values to serial monitor
Serial.print("X-axis: ");
Serial.print(xValue);
Serial.print("\tY-axis: ");
Serial.print(yValue);
Serial.print("\tButton: ");
Serial.println(buttonState);
delay(100); // Adjust delay as needed
}
Individual Task 2 (servo motor)¶
We were asked to move an output device called servo motor and cpntrol its movment base on some values on our codes. We could do this task by downloading the available example on Arduino IDE and just manpulate on it to reach to what we want.
Individual Task 3 (inout & output togather)¶
After seeing an example about controlling an input device as joystick, and dealing with an output device as servo motor, now it’s time to make some action with them. We have to program a code that control an output device by an inout device. in that case, I used the joystick as an input deivce and servo motor as an output device.
The idea was just changing the movement mechanism base on the type of input data that would be passed from the joystick (input deivce) to the servo motor (output deivce).