智能灯塔-Arduino中文社区 - Powered by Discuz! Archiver

笨狼 发表于 2017-10-18 22:47

智能灯塔

第一步,准备需要的LED灯和电阻,由于单片机供电电压是5v,LED灯需要电压为3.3v,所以需要在LED正极引脚串联100Ω电阻,连接好后,进行焊接修整。


第二步,对灯塔进行3D打印,打印好后进行简单模拟组装,之后将焊好电阻的LED灯粘到灯珠支架上。


第三步,给每个灯珠接线,并将所有灯珠、灯架安装到3D打印的灯塔上,从最高层开始制作,最终完成整座灯塔的灯珠安装工作。


第四步,重复以上步骤,完成4座灯塔的安装制作。为了解决不同层灯光影响问题,后期补加了黑色遮光板。



第五步,激光切割亚克力灯塔底座,并模拟布局安装。


第六步,连接电路,对每一个LED灯进行编号,并连接到arduino相应的引脚上,并将所有LED的负极接到一个接口上。


第七步,编写程序,比较简单,对灯进行编号,大部分工作是复制粘贴,然后进行小修改。


第八步,程序测试,作品展示。我在第一个灯塔的最上方加了一个紫色LED灯来表示秒,这个LED会亮一秒,灭一秒进行闪烁。


这个灯塔时钟通过灯光来表示时间,每个灯塔由下到上4个灯分别表示1,2,4,8。前两个灯塔表示小时,后两个灯塔表示分钟。
如上图所示,测试图片中的时间是2:42,展示图片中的时间是21:44.

以下是代码部分
int led0=18;//A4
int led1=19;//A5
int led2=2;
int led3=3;
int led4=4;
int led5=15;//A1
int led6=16;//A2
int led7=17;//A3
int led8=8;
int led9=9;
int led10=10;
int led11=11;
int led12=12;
int led13=13;
#include <stdio.h>
#include <string.h>
#include <DS1302.h>
/* 接口定义
CE(DS1302 pin5) -> Arduino D5
IO(DS1302 pin6) -> Arduino D6
SCLK(DS1302 pin7) -> Arduino D7
*/
uint8_t CE_PIN   = 5;
uint8_t IO_PIN   = 6;
uint8_t SCLK_PIN = 7;

/* 日期变量缓存 */
char buf;
char day;
/* 串口数据缓存 */
String comdata = "";
int numdata = {0}, j = 0, mark = 0;
/* 创建 DS1302 对象 */
DS1302 rtc(CE_PIN, IO_PIN, SCLK_PIN);
void print_time()
{
Time t = rtc.time();
memset(day, 0, sizeof(day));
switch (t.day)
{
case 1: strcpy(day, "Sunday"); break;
case 2: strcpy(day, "Monday"); break;
case 3: strcpy(day, "Tuesday"); break;
case 4: strcpy(day, "Wednesday"); break;
case 5: strcpy(day, "Thursday"); break;
case 6: strcpy(day, "Friday"); break;
case 7: strcpy(day, "Saturday"); break;
    }
snprintf(buf, sizeof(buf), "%s %04d-%02d-%02d %02d:%02d:%02d", day, t.yr, t.mon, t.date, t.hr, t.min, t.sec);
switch(t.hr){
case 0:
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
break;
case 1:
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, HIGH);
break;
case 2:
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, HIGH);
digitalWrite(led6, LOW);
break;
case 3:
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, HIGH);
digitalWrite(led6, HIGH);
break;
case 4:
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, HIGH);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
break;
case 5:
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, HIGH);
digitalWrite(led5, LOW);
digitalWrite(led6, HIGH);
break;
case 6:
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, HIGH);
digitalWrite(led5, HIGH);
digitalWrite(led6, LOW);
break;
case 7:
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, HIGH);
digitalWrite(led5, HIGH);
digitalWrite(led6, HIGH);
break;
case 8:
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
break;
case 9:
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, HIGH);
break;
case 10:
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
break;
case 11:
digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, HIGH);
break;
   case 12:
   digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, HIGH);
digitalWrite(led6, LOW);
break;
   case 13:
   digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, HIGH);
digitalWrite(led6, HIGH);
break;
   case 14:
   digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
digitalWrite(led4, HIGH);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
break;
   case 15:
   digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
digitalWrite(led4, HIGH);
digitalWrite(led5, LOW);
digitalWrite(led6, HIGH);
break;
   case 16:
   digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
digitalWrite(led4, HIGH);
digitalWrite(led5, HIGH);
digitalWrite(led6, LOW);
break;
   case 17:
   digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led3, LOW);
digitalWrite(led4, HIGH);
digitalWrite(led5, HIGH);
digitalWrite(led6, HIGH);
break;
   case 18:
   digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
break;
   case 19:
   digitalWrite(led1, LOW);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, HIGH);
break;
   case 20:
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
break;
case 21:
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, HIGH);
break;
case 22:
   digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, HIGH);
digitalWrite(led6, LOW);
break;
case 23:
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, HIGH);
digitalWrite(led6, HIGH);
break;
    }

switch(t.min){
case 0:
digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
digitalWrite(led10, LOW);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
digitalWrite(led13, LOW);
break;
case 1:
digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
digitalWrite(led10, LOW);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
digitalWrite(led13, HIGH);
break;
case 2:
digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
digitalWrite(led10, LOW);
digitalWrite(led11, LOW);
digitalWrite(led12, HIGH);
digitalWrite(led13, LOW);
break;
case 3:
digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
digitalWrite(led10, LOW);
digitalWrite(led11, LOW);
digitalWrite(led12, HIGH);
digitalWrite(led13, HIGH);
break;
case 4:
digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
digitalWrite(led10, LOW);
digitalWrite(led11, HIGH);
digitalWrite(led12, LOW);
digitalWrite(led13, LOW);
break;
case 5:
digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
digitalWrite(led10, LOW);
digitalWrite(led11, HIGH);
digitalWrite(led12, LOW);
digitalWrite(led13, HIGH);
break;
case 6:
digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
digitalWrite(led10, LOW);
digitalWrite(led11, HIGH);
digitalWrite(led12, HIGH);
digitalWrite(led13, LOW);
break;
case 7:
digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
digitalWrite(led10, LOW);
digitalWrite(led11, HIGH);
digitalWrite(led12, HIGH);
digitalWrite(led13, HIGH);
break;
case 8:
digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
digitalWrite(led10, HIGH);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
digitalWrite(led13, LOW);
break;
case 9:
digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
digitalWrite(led10, HIGH);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
digitalWrite(led13, HIGH);
break;
case 10:
digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
digitalWrite(led9, HIGH);
digitalWrite(led10, LOW);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
digitalWrite(led13, LOW);
break;
case 11:
   digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
digitalWrite(led9, HIGH);
digitalWrite(led10, LOW);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
digitalWrite(led13, HIGH);
break;
   case 12:
    digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
digitalWrite(led9, HIGH);
digitalWrite(led10, LOW);
digitalWrite(led11, LOW);
digitalWrite(led12, HIGH);
digitalWrite(led13, LOW);
break;
   case 13:
    digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
digitalWrite(led9, HIGH);
digitalWrite(led10, LOW);
digitalWrite(led11, LOW);
digitalWrite(led12, HIGH);
digitalWrite(led13, HIGH);
break;
   case 14:
    digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
digitalWrite(led9, HIGH);
digitalWrite(led10, LOW);
digitalWrite(led11, HIGH);
digitalWrite(led12, LOW);
digitalWrite(led13, LOW);
break;
   case 15:
    digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
digitalWrite(led9, HIGH);
digitalWrite(led10, LOW);
digitalWrite(led11, HIGH);
digitalWrite(led12, LOW);
digitalWrite(led13, HIGH);
break;
   case 16:
    digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
digitalWrite(led9, HIGH);
digitalWrite(led10, LOW);
digitalWrite(led11, HIGH);
digitalWrite(led12, HIGH);
digitalWrite(led13, LOW);
break;
   case 17:
    digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
digitalWrite(led9, HIGH);
digitalWrite(led10, LOW);
digitalWrite(led11, HIGH);
digitalWrite(led12, HIGH);
digitalWrite(led13, HIGH);
break;
   case 18:
    digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
digitalWrite(led9, HIGH);
digitalWrite(led10, HIGH);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
digitalWrite(led13, LOW);
break;
   case 19:
    digitalWrite(led7, LOW);
digitalWrite(led8, LOW);
digitalWrite(led9, HIGH);
digitalWrite(led10, HIGH);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
digitalWrite(led13, HIGH);
break;
   case 20:
    digitalWrite(led7, LOW);
digitalWrite(led8, HIGH);
digitalWrite(led9, LOW);
digitalWrite(led10, LOW);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
digitalWrite(led13, LOW);
break;
case 21:
   digitalWrite(led7, LOW);
digitalWrite(led8, HIGH);
digitalWrite(led9, LOW);
digitalWrite(led10, LOW);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
digitalWrite(led13, HIGH);
break;
   case 22:
    digitalWrite(led7, LOW);
digitalWrite(led8, HIGH);
digitalWrite(led9, LOW);
digitalWrite(led10, LOW);
digitalWrite(led11, LOW);
digitalWrite(led12, HIGH);
digitalWrite(led13, LOW);
break;
   case 23:
    digitalWrite(led7, LOW);
digitalWrite(led8, HIGH);
digitalWrite(led9, LOW);
digitalWrite(led10, LOW);
digitalWrite(led11, LOW);
digitalWrite(led12, HIGH);
digitalWrite(led13, HIGH);
break;
   case 24:
    digitalWrite(led7, LOW);
digitalWrite(led8, HIGH);
digitalWrite(led9, LOW);
digitalWrite(led10, LOW);
digitalWrite(led11, HIGH);
digitalWrite(led12, LOW);
digitalWrite(led13, LOW);
break;
   case 25:
    digitalWrite(led7, LOW);
digitalWrite(led8, HIGH);
digitalWrite(led9, LOW);
digitalWrite(led10, LOW);
digitalWrite(led11, HIGH);
digitalWrite(led12, LOW);
digitalWrite(led13, HIGH);
break;
   case 26:
    digitalWrite(led7, LOW);
digitalWrite(led8, HIGH);
digitalWrite(led9, LOW);
digitalWrite(led10, LOW);
digitalWrite(led11, HIGH);
digitalWrite(led12, HIGH);
digitalWrite(led13, LOW);
break;
   case 27:
    digitalWrite(led7, LOW);
digitalWrite(led8, HIGH);
digitalWrite(led9, LOW);
digitalWrite(led10, LOW);
digitalWrite(led11, HIGH);
digitalWrite(led12, HIGH);
digitalWrite(led13, HIGH);
break;
   case 28:
    digitalWrite(led7, LOW);
digitalWrite(led8, HIGH);
digitalWrite(led9, LOW);
digitalWrite(led10, HIGH);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
digitalWrite(led13, LOW);
break;
   case 29:
    digitalWrite(led7, LOW);
digitalWrite(led8, HIGH);
digitalWrite(led9, LOW);
digitalWrite(led10, HIGH);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
digitalWrite(led13, HIGH);
break;
   case 30:
    digitalWrite(led7, LOW);
digitalWrite(led8, HIGH);
digitalWrite(led9, HIGH);
digitalWrite(led10, LOW);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
digitalWrite(led13, LOW);
break;
   case 31:
   digitalWrite(led7, LOW);
digitalWrite(led8, HIGH);
digitalWrite(led9, HIGH);
digitalWrite(led10, LOW);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
digitalWrite(led13, HIGH);
break;
   case 32:
    digitalWrite(led7, LOW);
digitalWrite(led8, HIGH);
digitalWrite(led9, HIGH);
digitalWrite(led10, LOW);
digitalWrite(led11, LOW);
digitalWrite(led12, HIGH);
digitalWrite(led13, LOW);
break;
   case 33:
    digitalWrite(led7, LOW);
digitalWrite(led8, HIGH);
digitalWrite(led9, HIGH);
digitalWrite(led10, LOW);
digitalWrite(led11, LOW);
digitalWrite(led12, HIGH);
digitalWrite(led13, HIGH);
break;
   case 34:
    digitalWrite(led7, LOW);
digitalWrite(led8, HIGH);
digitalWrite(led9, HIGH);
digitalWrite(led10, LOW);
digitalWrite(led11, HIGH);
digitalWrite(led12, LOW);
digitalWrite(led13, LOW);
break;
   case 35:
    digitalWrite(led7, LOW);
digitalWrite(led8, HIGH);
digitalWrite(led9, HIGH);
digitalWrite(led10, LOW);
digitalWrite(led11, HIGH);
digitalWrite(led12, LOW);
digitalWrite(led13, HIGH);
break;
   case 36:
    digitalWrite(led7, LOW);
digitalWrite(led8, HIGH);
digitalWrite(led9, HIGH);
digitalWrite(led10, LOW);
digitalWrite(led11, HIGH);
digitalWrite(led12, HIGH);
digitalWrite(led13, LOW);
break;
   case 37:
    digitalWrite(led7, LOW);
digitalWrite(led8, HIGH);
digitalWrite(led9, HIGH);
digitalWrite(led10, LOW);
digitalWrite(led11, HIGH);
digitalWrite(led12, HIGH);
digitalWrite(led13, HIGH);
break;
   case 38:
    digitalWrite(led7, LOW);
digitalWrite(led8, HIGH);
digitalWrite(led9, HIGH);
digitalWrite(led10, HIGH);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
digitalWrite(led13, LOW);
break;
   case 39:
    digitalWrite(led7, LOW);
digitalWrite(led8, HIGH);
digitalWrite(led9, HIGH);
digitalWrite(led10, HIGH);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
digitalWrite(led13, HIGH);
break;
   case 40:
    digitalWrite(led7, HIGH);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
digitalWrite(led10, LOW);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
digitalWrite(led13, LOW);
break;
   case 41:
digitalWrite(led7, HIGH);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
digitalWrite(led10, LOW);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
digitalWrite(led13, HIGH);
break;
   case 42:
    digitalWrite(led7, HIGH);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
digitalWrite(led10, LOW);
digitalWrite(led11, LOW);
digitalWrite(led12, HIGH);
digitalWrite(led13, LOW);
break;
   case 43:
   digitalWrite(led7, HIGH);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
digitalWrite(led10, LOW);
digitalWrite(led11, LOW);
digitalWrite(led12, HIGH);
digitalWrite(led13, HIGH);
break;
   case 44:
   digitalWrite(led7, HIGH);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
digitalWrite(led10, LOW);
digitalWrite(led11, HIGH);
digitalWrite(led12, LOW);
digitalWrite(led13, LOW);
break;
   case 45:
   digitalWrite(led7, HIGH);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
digitalWrite(led10, LOW);
digitalWrite(led11, HIGH);
digitalWrite(led12, LOW);
digitalWrite(led13, HIGH);
break;
   case 46:
    digitalWrite(led7, HIGH);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
digitalWrite(led10, LOW);
digitalWrite(led11, HIGH);
digitalWrite(led12, HIGH);
digitalWrite(led13, LOW);
break;
   case 47:
    digitalWrite(led7, HIGH);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
digitalWrite(led10, LOW);
digitalWrite(led11, HIGH);
digitalWrite(led12, HIGH);
digitalWrite(led13, HIGH);
break;
   case 48:
    digitalWrite(led7, HIGH);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
digitalWrite(led10, HIGH);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
digitalWrite(led13, LOW);
break;
   case 49:
    digitalWrite(led7, HIGH);
digitalWrite(led8, LOW);
digitalWrite(led9, LOW);
digitalWrite(led10, HIGH);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
digitalWrite(led13, HIGH);
break;
   case 50:
    digitalWrite(led7, HIGH);
digitalWrite(led8, LOW);
digitalWrite(led9, HIGH);
digitalWrite(led10, LOW);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
digitalWrite(led13, LOW);
break;
   case 51:
   digitalWrite(led7, HIGH);
digitalWrite(led8, LOW);
digitalWrite(led9, HIGH);
digitalWrite(led10, LOW);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
digitalWrite(led13, HIGH);
break;
   case 52:
   digitalWrite(led7, HIGH);
digitalWrite(led8, LOW);
digitalWrite(led9, HIGH);
digitalWrite(led10, LOW);
digitalWrite(led11, LOW);
digitalWrite(led12, HIGH);
digitalWrite(led13, LOW);
break;
   case 53:
digitalWrite(led7, HIGH);
digitalWrite(led8, LOW);
digitalWrite(led9, HIGH);
digitalWrite(led10, LOW);
digitalWrite(led11, LOW);
digitalWrite(led12, HIGH);
digitalWrite(led13, HIGH);
break;
   case 54:
digitalWrite(led7, HIGH);
digitalWrite(led8, LOW);
digitalWrite(led9, HIGH);
digitalWrite(led10, LOW);
digitalWrite(led11, HIGH);
digitalWrite(led12, LOW);
digitalWrite(led13, LOW);
break;
   case 55:
   digitalWrite(led7, HIGH);
digitalWrite(led8, LOW);
digitalWrite(led9, HIGH);
digitalWrite(led10, LOW);
digitalWrite(led11, HIGH);
digitalWrite(led12, LOW);
digitalWrite(led13, HIGH);
break;
   case 56:
digitalWrite(led7, HIGH);
digitalWrite(led8, LOW);
digitalWrite(led9, HIGH);
digitalWrite(led10, LOW);
digitalWrite(led11, HIGH);
digitalWrite(led12, HIGH);
digitalWrite(led13, LOW);
break;
   case 57:
   digitalWrite(led7, HIGH);
digitalWrite(led8, LOW);
digitalWrite(led9, HIGH);
digitalWrite(led10, LOW);
digitalWrite(led11, HIGH);
digitalWrite(led12, HIGH);
digitalWrite(led13, HIGH);
break;
   case 58:
digitalWrite(led7, HIGH);
digitalWrite(led8, LOW);
digitalWrite(led9, HIGH);
digitalWrite(led10, HIGH);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
digitalWrite(led13, LOW);
break;
   case 59:
digitalWrite(led7, HIGH);
digitalWrite(led8, LOW);
digitalWrite(led9, HIGH);
digitalWrite(led10, HIGH);
digitalWrite(led11, LOW);
digitalWrite(led12, LOW);
digitalWrite(led13, HIGH);
break;
    }

if(t.sec%2==1){
digitalWrite(led0, HIGH);
}else
{
    digitalWrite(led0, LOW);
    }

Serial.println(buf);
}

void setup()
{
pinMode(led0, OUTPUT);//定义小灯接口为输出接口
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(led6, OUTPUT);
pinMode(led7, OUTPUT);
pinMode(led8, OUTPUT);
pinMode(led9, OUTPUT);
pinMode(led10, OUTPUT);
pinMode(led11, OUTPUT);
pinMode(led12, OUTPUT);
pinMode(led13, OUTPUT);

Serial.begin(9600);
rtc.write_protect(false);
rtc.halt(false);
}

void loop()
{
while (Serial.available() > 0)
{
comdata += char(Serial.read());
delay(2);
mark = 1;

}
if (mark == 1)
{
Serial.print("You inputed : ");
Serial.println(comdata);
for (int i = 0; i < comdata.length() ; i++)
{
if (comdata == ',' || comdata == 0x10 || comdata == 0x13)
{
j++;
      }
else
{
numdata = numdata * 10 + (comdata - '0');
      }
}
Time t(numdata, numdata, numdata, numdata, numdata, numdata, numdata);
rtc.time(t);
mark = 0; j = 0;
comdata = String("");
for (int i = 0; i < 7 ; i++) numdata = 0;
}
print_time();
delay(500);
}


视频正在审核中,审核后会放出来,大家可以看看我之前做到小东西。一个是4级加速电磁炮,一个是6足小机器人。
http://v.youku.com/v_show/id_XMjczMjI4NjI5Ng==.html?spm=a2h3j.8428770.3416059.1

希望大家喜欢,投我一票呀~~~

笨狼 发表于 2017-10-19 09:14

灯塔演示视频

单片机菜鸟 发表于 2017-10-19 09:16

其实 写完代码之后你应该考虑一下是否可以优化代码 因为我看到好多感觉重复代码

跑龙套的保 发表于 2017-10-19 15:32

这扣腚真不优雅:(

syl312 发表于 2017-10-26 22:39

1.感谢对社区比赛的支持,开发者积分和贡献值已发放,请点击以下链接领取纪念衫并参与抽奖~
http://www.arduino.cn/thread-48132-1-1.html
2.比赛结果会在11.15号前公布,请耐心等待。

笨狼 发表于 2017-10-26 23:07

http://v.youku.com/v_show/id_XMzExMjg5MTY4OA==.html?spm=a2h3j.8428770.3416059.1
灯塔时钟小时变化

笨狼 发表于 2017-11-21 12:05

衣服收到,棒棒的。

明娃子 发表于 2018-9-14 08:21

好贴 谢谢分享
页: [1]
查看完整版本: 智能灯塔