物联网起步----esp8266本地点灯

3 篇文章 0 订阅
2 篇文章 0 订阅

准备

物联网编程,不像我们纯粹的软件编程,还需要硬件的支持。

硬件准备

需要esp8266板子一个,杜邦线若干条。(这是必须的)
我这里有一个三色LED ( KY-016 3色 LED),就拿它来试试手。

ky-016  三色LED

通讯准备

esp8266用数据线直连电脑是COM通讯的,直接连接电脑usb后,板子电源灯常亮,(如果不亮就要看看板子说明书了),这时候

右击我的电脑
管理
系统工具
设备管理器
端口COM和LPT

设备管理器端口查看
记住 端口号 !!!

打开Arduino进行端口设置:

打开Arduino
工具
端口
选择对应端口号

端口设置

程序上手

GPIO点选择

选择的三色灯,需要三正一负。就随便选D2(GPIO4)、D3(GPIO0)、D4(GPIO2)、GND;

在这里插入图片描述

完整代码

/*
 ESP8266 Blink by Simon Peter
 Blink the blue LED on the ESP-01 module
 This example code is in the public domain
 
 The blue LED on the ESP-01 module is connected to GPIO1 
 (which is also the TXD pin; so we cannot use Serial.print() at the same time)
 
 Note that this sketch uses BUILTIN_LED to find the pin with the internal LED
*/
int LED_PIN2 = 2;//GPIO2
int LED_PIN3 = 0;//GPIO0
int LED_PIN4 = 4;//GPIO4
void setup() 
{
  Serial.begin(115200);
  pinMode(LED_PIN2, OUTPUT);     // Initialize the BUILTIN_LED pin as an output
   pinMode(LED_PIN3, OUTPUT);
    pinMode(LED_PIN4, OUTPUT);
}

// the loop function runs over and over again forever
void loop() 
{
  int i=0;
  for(i;i<8;i++)
  {
  switch(i)
  {
    case 0:
    
  digitalWrite(LED_PIN2, 0);   // Turn the LED on (Note that LOW is the voltage level
  digitalWrite(LED_PIN3, 0);
  digitalWrite(LED_PIN4, 0);
  break;
      case 1:
    
  digitalWrite(LED_PIN2, 0);   // Turn the LED on (Note that LOW is the voltage level
  digitalWrite(LED_PIN3, 0);
  digitalWrite(LED_PIN4, 1);
    break;
        case 2:
    
  digitalWrite(LED_PIN2, 0);   // Turn the LED on (Note that LOW is the voltage level
  digitalWrite(LED_PIN3, 1);
  digitalWrite(LED_PIN4, 0);
    break;
        case 3:
    
  digitalWrite(LED_PIN2, 0);   // Turn the LED on (Note that LOW is the voltage level
  digitalWrite(LED_PIN3, 1);
  digitalWrite(LED_PIN4, 1);
    break;
        case 4:
    
  digitalWrite(LED_PIN2, 1);   // Turn the LED on (Note that LOW is the voltage level
  digitalWrite(LED_PIN3, 0);
  digitalWrite(LED_PIN4, 0);
    break;
        case 5:
    
  digitalWrite(LED_PIN2, 1);   // Turn the LED on (Note that LOW is the voltage level
  digitalWrite(LED_PIN3, 0);
  digitalWrite(LED_PIN4, 1);
    break;
        case 6:
    
  digitalWrite(LED_PIN2, 1);   // Turn the LED on (Note that LOW is the voltage level
  digitalWrite(LED_PIN3, 1);
  digitalWrite(LED_PIN4, 0);
    break;
        case 7:
    
  digitalWrite(LED_PIN2, 1);   // Turn the LED on (Note that LOW is the voltage level
  digitalWrite(LED_PIN3, 1);
  digitalWrite(LED_PIN4, 1);
    break;
  

  }
    delay(1000);      //间隔1000ms也就是1秒
  }
}


上传代码

编译 验证没问题就可以上传代码了,有了前面的准备和代码,我们就可以直接上传了。

按住esp8266板子上的 FLASH 按钮,点击上传,等出现上传进度 …。。。后可以松开 FLASH 按钮,继续等待上传完成。
在这里插入图片描述

最后的效果

ipqchase

最后 :感谢我们 胡工 一直以来的指导

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ipqchase85

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值