Tarea3 Microcontroladores - Lovera
Tarea3 Microcontroladores - Lovera
Tarea3 Microcontroladores - Lovera
Trabajo de Investigación
#define SPEAKER_PIN 8
void setup() {
for (uint8_t i = 0; i < numTones; i++) {
pinMode(buttonPins[i], INPUT_PULLUP);
}
pinMode(SPEAKER_PIN, OUTPUT);
}
void loop() {
int pitch = 0;
for (uint8_t i = 0; i < numTones; i++) {
if (digitalRead(buttonPins[i]) == LOW) {
pitch = buttonTones[i];
}
}
if (pitch) {
tone(SPEAKER_PIN, pitch);
} else {
noTone(SPEAKER_PIN);
}
delay(10);
}
2Ejemplo:
#define DIR_PIN 2
#define STEP_PIN 3
void setup() {
pinMode(STEP_PIN, OUTPUT);
pinMode(DIR_PIN, OUTPUT);
digitalWrite(STEP_PIN, LOW);
}
void loop() {
// Move 200 steps (one rotation) CW over one second
digitalWrite(DIR_PIN, HIGH);
for (int i = 0; i < 200; i++) {
digitalWrite(STEP_PIN, HIGH);
digitalWrite(STEP_PIN, LOW);
delay(5); // 5 ms * 200 = 1 second
}
void spinner() {
static int8_t counter = 0;
const char* glyphs = "\xa1\xa5\xdb";
LCD.setCursor(15, 1);
LCD.print(glyphs[counter++]);
if (counter == strlen(glyphs)) {
counter = 0;
}
}
void printLocalTime() {
struct tm timeinfo;
if (!getLocalTime(&timeinfo)) {
LCD.setCursor(0, 1);
LCD.println("Connection Err");
return;
}
LCD.setCursor(8, 0);
LCD.println(&timeinfo, "%H:%M:%S");
LCD.setCursor(0, 1);
LCD.println(&timeinfo, "%d/%m/%Y %Z");
}
void setup() {
Serial.begin(115200);
LCD.init();
LCD.backlight();
LCD.setCursor(0, 0);
LCD.print("Connecting to ");
LCD.setCursor(0, 1);
LCD.print("WiFi ");
Serial.println("");
Serial.println("WiFi connected");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
LCD.clear();
LCD.setCursor(0, 0);
LCD.println("Online");
LCD.setCursor(0, 1);
LCD.println("Updating time...");
void loop() {
printLocalTime();
delay(250);
}
2Ejemplo:
#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#define BTN_PIN 5
#define TFT_DC 2
#define TFT_CS 15
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
String getJoke() {
HTTPClient http;
http.useHTTP10(true);
http.begin(url);
http.GET();
String result = http.getString();
DynamicJsonDocument doc(2048);
DeserializationError error = deserializeJson(doc, result);
void nextJoke() {
tft.setTextColor(ILI9341_WHITE);
tft.println("\nLoading joke...");
void setup() {
pinMode(BTN_PIN, INPUT_PULLUP);
tft.begin();
tft.setRotation(1);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.print("Connecting to WiFi");
tft.print("\nOK! IP=");
tft.println(WiFi.localIP());
nextJoke();
}
void loop() {
if (digitalRead(BTN_PIN) == LOW) {
tft.fillScreen(ILI9341_BLACK);
tft.setCursor(0, 0);
nextJoke();
}
delay(100);
}
II. EJERCICIO Nº2: Publicar en internet el sensor DHT11 con el ESP32 utilizando la
página de ThingSpeak. Puede utilizar la siguiente página de referencia
https://www.youtube.com/watch?v=P1D3kkcNuMU
(8 puntos)
import machine
import dht
import time
import network
import urequests as requests
# Connect to Wi-Fi
def Connect_WiFi():
net = network.WLAN(network.STA_IF)
if not net.isconnected():
net.active(True)
net.connect("your_SSID", "your_PASSWORD")
print(net.ifconfig())
# Main loop
while True:
Connect_WiFi()
time.sleep(1)
(t, h) = TempHum()
Send_Data(t, h)
time.sleep(30)