DES 325 A
Analog Output Experimentation
Part 1:
Was able to successfully get the photoresistor to detect a change in light which would directly affect the dimness of the LED. The change in dimness was extremely subtle. I decided to increase the resistance to make the light more sensitive to the photoresistor. From a 220 ohm resistor, I changed it to a 2K ohm resistor and it made a significant difference. I was even able to see the delay more clearly with the new resistor. See below:
Part 2: LED controlled by Joystick
Well, the original plan was to experiment with the joystick to control the LED lights and then try using photoresistors to replace the joystick to turn on certain lights as to mimic current game controllers that use sensors to control movement and the display. Unfortunately... I could not even get the arduino to really work. It is difficult without much guidance even though I had a tutorial. Hopefully I learn my mistake soon.
Add caption |
Here is the code that I used (thanks to https://www.instructables.com/id/Connect-and-Use-Joystick-With-Arduino/):
int UD = 0;
int LR = 0;
/* Arduino Micro output pins*/
int DWN = 13;
int UP = 12;
int LEFT = 11;
int RT = 10;
/*Arduino Micro Input Pins */
int IUP=A0;
int ILR=A1;
int MID = 10; // 10 mid point delta arduino, use 4 for attiny
int LRMID = 0;
int UPMID = 0;
void setup(){
pinMode(DWN, OUTPUT);
pinMode(UP, OUTPUT);
pinMode(LEFT, OUTPUT);
pinMode(RT, OUTPUT);
digitalWrite(DWN, HIGH);
digitalWrite(UP, HIGH);
digitalWrite(LEFT, HIGH);
digitalWrite(RT, HIGH);
//calabrate center
LRMID = analogRead(ILR);
UPMID = analogRead(IUP); }
void loop(){
UD = analogRead(IUP);
LR = analogRead(ILR);
// UP-DOWN
if(UD < UPMID - MID){
digitalWrite(DWN, HIGH);
}else{
digitalWrite(DWN, LOW);
}
if(UD > UPMID + MID)
{ digitalWrite(UP, HIGH);
}else{
digitalWrite(UP, LOW);
} // LEFT-RIGHT
if(LR < LRMID - MID){
digitalWrite(LEFT, HIGH);
}else{
digitalWrite(LEFT, LOW);
}
if(LR > LRMID + MID){
digitalWrite(RT, HIGH);
}else{
digitalWrite(RT, LOW);
}
delay(400);
}
No comments:
Post a Comment