arduino ESP32 002 wokwi在线仿真点亮小灯

发布时间:2024年01月03日

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

点亮小灯

ESP-IDF

在这里插入图片描述

#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"

#define PIN_LED_1 GPIO_NUM_16


void setup() {
    // 设置LED引脚为输出
    gpio_reset_pin(PIN_LED_1);
    // esp_rom_gpio_pad_select_gpio(PIN_LED_1);//IO Pad 配置为通用输入输出模式 https://github.com/espressif/esp-idf/blob/master/components/esp_rom/include/esp_rom_gpio.h
    gpio_set_direction(PIN_LED_1, GPIO_MODE_OUTPUT);// 将 PIN_LED_1 引脚配置为输出模式
}

void app_main() {
    setup();
    for(int i=0;i<100;i++){
      // 点亮LED
      gpio_set_level(PIN_LED_1, 1); // 将该 GPIO 引脚的电平设置为高电平
      vTaskDelay(1000 / portTICK_PERIOD_MS);
      gpio_set_level(PIN_LED_1, 0);
      vTaskDelay(1000 / portTICK_PERIOD_MS);
    }
}

Arduino开发环境

在这里插入图片描述

#include <Arduino.h>
#include <stdio.h>
// 定义LED引脚
int pinled = 4;
int pinled_2 = 16;
int pinled_3 = 17;

void setup() {
  // 初始化串口通信
  Serial.begin(115200);

  // 设置LED引脚为输出
  pinMode(pinled, OUTPUT);
  pinMode(pinled_2, OUTPUT);
  pinMode(pinled_3, OUTPUT);
}

void loop() {
  // 点亮第一个LED
  digitalWrite(pinled, HIGH);
  delay(1000); // 延迟1秒
  digitalWrite(pinled, LOW);

  // 点亮第二个LED
  digitalWrite(pinled_2, HIGH);
  delay(1000); // 延迟1秒
  digitalWrite(pinled_2, LOW);

  // 点亮第三个LED
  digitalWrite(pinled_3, HIGH);
  delay(1000); // 延迟1秒
  digitalWrite(pinled_3, LOW);
}

python

在这里插入图片描述

# https://wokwi.com/projects/359801682833812481
from machine import Pin
from utime import sleep

print("Hello, ESP32!")

led = Pin(15, Pin.OUT)
while True:
  led.on()
  sleep(0.5)
  led.off()
  sleep(0.5)

RUST

在这里插入图片描述

//! Blinks an LED  https://wokwi.com/projects/341952826535051858
//!
//! This assumes that a LED is connected to the pin assigned to `led`. (GPIO4)

#![no_std]
#![no_main]

use esp_backtrace as _;
use esp_println::println;
use hal::{clock::ClockControl, gpio::IO, peripherals::Peripherals, prelude::*, Delay};

#[entry]
fn main() -> ! {
    let peripherals = Peripherals::take();
    let system = peripherals.SYSTEM.split();
    let clocks = ClockControl::boot_defaults(system.clock_control).freeze();

    // Set GPIO4 as an output, and set its state high initially.
    let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
    let mut led = io.pins.gpio4.into_push_pull_output();

    led.set_high().unwrap();

    // Initialize the Delay peripheral, and use it to toggle the LED state in a
    // loop.
    let mut delay = Delay::new(&clocks);
    println!("Hello world!");
    loop {
        delay.delay_ms(1000u32);
        led.toggle().unwrap();
    }
}

CG

文章来源:https://blog.csdn.net/ResumeProject/article/details/135369129
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。