Last active
November 21, 2019 17:05
-
-
Save naranjja/fbab0c0bd8a8a46dc3f681456f3e2b4d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int pot = A0; // potentiometer | |
const int led = D8; | |
int potValue = 0; | |
long timestamp; | |
void setup () { | |
Serial.begin(9600); | |
Serial.println("Initializing..."); | |
timestamp = millis(); | |
} | |
void loop () { | |
// instead of using delay, check every 20 milliseconds | |
if (millis() - timestamp >= 20) { | |
potValue = analogRead(pot); | |
Serial.print("Potentiometer value: "); | |
Serial.println(potValue); | |
analogWrite(led, potValue); // send potentiometer value to led | |
timestamp = millis(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int pot = A0; // potentiometer | |
int potValue = 0; | |
void setup () { | |
Serial.begin(9600); | |
Serial.println("Initializing..."); | |
} | |
void loop () { | |
potValue = analogRead(pot); | |
Serial.print("Potentiometer value: "); | |
Serial.println(potValue); | |
delay(2000); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int pot = A0; // potentiometer | |
const int led = D8; | |
int potValue = 0; | |
long timestamp; | |
void setup () { | |
Serial.begin(9600); | |
Serial.println("Initializing..."); | |
timestamp = millis(); | |
} | |
void loop () { | |
// instead of using delay, check every 20 milliseconds | |
if (millis() - timestamp >= 20) { | |
potValue = analogRead(pot); | |
Serial.print("Potentiometer value: "); | |
Serial.println(potValue); | |
analogWrite(led, potValue); // send potentiometer value to led | |
delay(300); | |
digitalWrite(led, LOW); | |
delay(300); | |
timestamp = millis(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int led = D6; // D6 es donde conectamos el led | |
// OUTPUT es un int que ya esta definido en arduino | |
// HIGH es un int que significa 1, LOW, 0 | |
void setup() { | |
// put your setup code here, to run once: | |
pinMode(led, OUTPUT); | |
//digitalWrite(led, HIGH); | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
digitalWrite(led, HIGH); | |
delay(1000); | |
digitalWrite(led, LOW); | |
delay(1000); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int buttonState = 0; | |
int button = D1; | |
int led = D6; | |
void setup() { | |
pinMode(led, OUTPUT); | |
pinMode(button, INPUT); // boton en D1 es input | |
digitalWrite(led, LOW); // led apagado al comienzo | |
} | |
void loop() { | |
buttonState = digitalRead(button); | |
if (buttonState == HIGH) { // cuando apretas el boton que parpadee | |
digitalWrite(led, HIGH); | |
delay(500); | |
digitalWrite(led, LOW); | |
delay(500); | |
} else { | |
digitalWrite(led, LOW); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int buttonState = 0; | |
int button = D1; | |
int led = D6; | |
void setup() { | |
pinMode(led, OUTPUT); | |
pinMode(button, INPUT); // boton en D1 es input | |
digitalWrite(led, LOW); // led apagado al comienzo | |
} | |
void loop() { | |
buttonState = digitalRead(button); | |
digitalWrite(led, buttonState); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int buttonState = 0; | |
int button = D1; | |
int led = D6; | |
void setup() { | |
pinMode(led, OUTPUT); | |
pinMode(button, INPUT); // boton en D1 es input | |
digitalWrite(led, LOW); // led apagado al comienzo | |
} | |
void loop() { | |
buttonState = digitalRead(button); | |
if (buttonState == HIGH) { | |
digitalWrite(led, HIGH); | |
} else { | |
digitalWrite(led, LOW); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// state initialization | |
int buttonState = 0; | |
int ledState = 0; | |
int state = 0; | |
// pin references | |
int button = D1; | |
int led = D6; | |
void setup() { | |
// Serial object receives transfer rate as constructor parameter, traditionally 9600 bps | |
Serial.begin(9600); | |
Serial.println("Initializing..."); | |
Serial.println("Setting I/O pin modes..."); | |
pinMode(led, OUTPUT); | |
pinMode(button, INPUT); | |
Serial.println("Setting initial LED state to 0..."); | |
digitalWrite(led, 0); | |
} | |
void loop() { | |
buttonState = digitalRead(button); | |
if (buttonState == 1) { | |
state = 1; | |
} else { | |
if (state == 1) { | |
Serial.print("Changing led state to "); | |
state = 0; | |
if (ledState == 1) { | |
digitalWrite(led, 0); | |
ledState = 0; | |
Serial.println("0..."); | |
} else { | |
digitalWrite(led, 1); | |
ledState = 1; | |
Serial.println("1..."); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment