Initial commit
This commit is contained in:
12
analog.ino
Executable file
12
analog.ino
Executable file
@@ -0,0 +1,12 @@
|
|||||||
|
int sensorPin = A0;
|
||||||
|
int ledPin = 10;
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// read the value from the sensor:
|
||||||
|
int val = analogRead(sensorPin);
|
||||||
|
int output = map(val, 0, 1023, 0, 255);
|
||||||
|
analogWrite(ledPin, output);
|
||||||
|
}
|
||||||
53
joystick.ino
Executable file
53
joystick.ino
Executable file
@@ -0,0 +1,53 @@
|
|||||||
|
int switchPin = 11;
|
||||||
|
|
||||||
|
int izquierdaPin = 7;
|
||||||
|
int arribaPin = 6;
|
||||||
|
int derechaPin = 5;
|
||||||
|
int abajoPin = 4;
|
||||||
|
|
||||||
|
int ejeXPin = 0;
|
||||||
|
int ejeYPin = 1;
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
pinMode(izquierdaPin, OUTPUT);
|
||||||
|
pinMode(arribaPin, OUTPUT);
|
||||||
|
pinMode(derechaPin, OUTPUT);
|
||||||
|
pinMode(abajoPin, OUTPUT);
|
||||||
|
|
||||||
|
Serial.begin(9600);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
int ejeX = analogRead(ejeXPin);
|
||||||
|
int ejeY = analogRead(ejeYPin);
|
||||||
|
int switchValue = !digitalRead(switchPin);
|
||||||
|
|
||||||
|
Serial.print(switchValue);
|
||||||
|
Serial.print("\n");
|
||||||
|
if(ejeX >= 0 && ejeX <= 400 || switchValue) {
|
||||||
|
digitalWrite(izquierdaPin, HIGH);
|
||||||
|
}else{
|
||||||
|
digitalWrite(izquierdaPin, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ejeX >= 600 && ejeX <= 1023 || switchValue) {
|
||||||
|
digitalWrite(derechaPin, HIGH);
|
||||||
|
}else {
|
||||||
|
digitalWrite(derechaPin, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ejeY >= 0 && ejeY <= 400 || switchValue){
|
||||||
|
digitalWrite(abajoPin, HIGH);
|
||||||
|
} else {
|
||||||
|
digitalWrite(abajoPin, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(ejeY >= 600 && ejeY <= 1023 || switchValue) {
|
||||||
|
digitalWrite(arribaPin, HIGH);
|
||||||
|
} else {
|
||||||
|
digitalWrite(arribaPin, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// 0 - 1023\
|
||||||
Reference in New Issue
Block a user