7. Input & Output device¶
this week was completing on the previos week wich is embedded programming , or we can say that it is the second step of te embedded programming week .
what is input and output devices .¶
An input/output device, often known as an IO device, is any hardware that allows a human operator or other systems to interface with a computer. Input/output devices, as the name implies, are capable of delivering data (output) to and receiving data from a computer (input). An input/output (I/O) device is a piece of hardware that can take, output, or process data. It receives data as input and provides it to a computer, as well as sends computer data to storage media as a storage output.
what i lernd from input and output¶
1-i learned that The purpose of an input device is to enable computer operators to have control of the computer and send data such as text, images, or sounds to the computer
2- i knew the concept of the input devices and the sensors .
3- how can i enter an order to the input device to get answer from output device
program i used¶
the program that i used is Arduino IDE 1.8.19
what is Arduino IDE¶
Arduino programs are written in the Arduino Integrated Development Environment (IDE). Arduino IDE is a special software running on your system that allows you to write sketches (synonym for program in Arduino language) for different Arduino boards. The Arduino programming language is based on a very simple hardware programming language called processing, which is similar to the C language. After the sketch is written in the Arduino IDE, it should be uploaded on the Arduino board for execution.
problem i faced¶
one of the problem i faced is the wire connection, few times i do connect the wires wrong, but then i knew how to do it
input device¶
first i used the arduino to conicet it to my parts
then i choosed one of the input devices to conect it with the arduino
after that i chosed my device wich is the microphone
then i conected the wires to the part
then i enterd the code
code working on the mic sensor¶
#define mic 5
int maxfreq = 2000,minfreq = 900;
int state = 0;
bool New = true;
void setup() {
// put your setup code here, to run once:
pinMode(LED_BUILTIN, OUTPUT);
pinMode(mic, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
int freq = 1/(pulseIn(mic,HIGH));
if(freq > minfreq && freq < maxfreq && New){
if(state == 1){state = 0;}else{state = 1;}
New = false;
}else{
New = true;
}
digitalWrite(LED_BUILTIN,state);
}
output device¶
i used the code to run on the servo motor
code of running the servo motor¶
#include <Servo.h>
Servo myservo;
Define the servo pin:
#define servoPin 9
Create a variable to store the servo position:
int angle = 0;
void setup() {
Attach the Servo variable to a pin:
myservo.attach(servoPin);
}
void loop() {
// Tell the servo to go to a particular angle:
myservo.write(90);
delay(1000);
myservo.write(180);
delay(1000);
myservo.write(0);
delay(1000);
// Sweep from 0 to 180 degrees:
for (angle = 0; angle <= 180; angle += 1) {
myservo.write(angle);
delay(15);
}
// And back from 180 to 0 degrees:
for (angle = 180; angle >= 0; angle -= 1) {
myservo.write(angle);
delay(30);
}
delay(1000);
}