Devices & Components
Arduino Uno Rev3
Resistor 221 ohm
LEDs
Jumper wires (generic)
Breadboard (generic)
Buzzer
Analog joystick (Generic)
Project description
Code
SoftWare
c_cpp
1const int buzzer = 4; 2const int ledleft = 13; 3const int ledright = 8; 4const int ledbehind = 7; 5const int ledfront = 12; 6const int SW_pin = 2; 7const int X_pin = 0; 8const int Y_pin = 1; 9 10void setup() { 11 12 pinMode(buzzer, OUTPUT); 13 pinMode(ledleft, OUTPUT); 14 pinMode(ledright, OUTPUT); 15 pinMode(ledbehind, OUTPUT); 16 pinMode(ledfront, OUTPUT); 17 18 pinMode(SW_pin, INPUT); 19 digitalWrite(SW_pin, HIGH); 20 Serial.begin(9600); 21} 22 23void loop() { 24 25 int position_x = analogRead(X_pin); 26 int position_y = analogRead(Y_pin); 27 int switch_status = digitalRead(SW_pin); 28 29 Serial.print("Switch: "); 30 Serial.print(digitalRead(SW_pin)); 31 Serial.print("\ 32"); 33 Serial.print("X-axis: "); 34 Serial.print(analogRead(X_pin)); 35 Serial.print("\ 36"); 37 Serial.print("Y-axis: "); 38 Serial.println(analogRead(Y_pin)); 39 Serial.print("\ 40\ 41"); 42 delay(1); 43 44 if (switch_status == 0){ 45 digitalWrite (buzzer, HIGH); 46 } 47 else { 48 digitalWrite (buzzer, LOW); 49 } 50 if (position_x <= 500) { 51 digitalWrite (ledbehind, HIGH); 52 } 53 else { 54 digitalWrite (ledbehind, LOW); 55 } 56 if (position_x >= 520) { 57 digitalWrite (ledfront, HIGH); 58 } 59 else { 60 digitalWrite (ledfront, LOW); 61 } 62if (position_y >= 520) { 63 digitalWrite (ledright, HIGH); 64} 65else { 66 digitalWrite (ledright, LOW); 67} 68 if (position_y <=500) { 69 digitalWrite (ledleft, HIGH); 70 } 71 else { 72 digitalWrite (ledleft, LOW); 73 } 74}
SoftWare
c_cpp
1const int buzzer = 4; 2const int ledleft = 13; 3const int ledright = 8; 4const int ledbehind = 7; 5const int ledfront = 12; 6const int SW_pin = 2; 7const int X_pin = 0; 8const int Y_pin = 1; 9 10void setup() { 11 12 pinMode(buzzer, OUTPUT); 13 pinMode(ledleft, OUTPUT); 14 pinMode(ledright, OUTPUT); 15 pinMode(ledbehind, OUTPUT); 16 pinMode(ledfront, OUTPUT); 17 18 pinMode(SW_pin, INPUT); 19 digitalWrite(SW_pin, HIGH); 20 Serial.begin(9600); 21} 22 23void loop() { 24 25 int position_x = analogRead(X_pin); 26 int position_y = analogRead(Y_pin); 27 int switch_status = digitalRead(SW_pin); 28 29 Serial.print("Switch: "); 30 Serial.print(digitalRead(SW_pin)); 31 Serial.print("\ 32"); 33 Serial.print("X-axis: "); 34 Serial.print(analogRead(X_pin)); 35 Serial.print("\ 36"); 37 Serial.print("Y-axis: "); 38 Serial.println(analogRead(Y_pin)); 39 Serial.print("\ 40\ 41"); 42 delay(1); 43 44 if (switch_status == 0){ 45 digitalWrite (buzzer, HIGH); 46 } 47 else { 48 digitalWrite (buzzer, LOW); 49 } 50 if (position_x <= 500) { 51 digitalWrite (ledbehind, HIGH); 52 } 53 else { 54 digitalWrite (ledbehind, LOW); 55 } 56 if (position_x >= 520) { 57 digitalWrite (ledfront, HIGH); 58 } 59 else { 60 digitalWrite (ledfront, LOW); 61 } 62if (position_y >= 520) { 63 digitalWrite (ledright, HIGH); 64} 65else { 66 digitalWrite (ledright, LOW); 67} 68 if (position_y <=500) { 69 digitalWrite (ledleft, HIGH); 70 } 71 else { 72 digitalWrite (ledleft, LOW); 73 } 74}
Downloadable files
HardWare
The BUZZER goes to the pin "4"
HardWare

Comments
Only logged in users can leave comments