所有分类
主题 主题
平台 平台
我的工作台
userHead
注册时间 [[userInfo.create_time]]
创造力 [[userInfo.creativity]]
[[userInfo.remark]]
[[d.project_title]]
articleThumb
[[d.material_name]]
timelineThumb
进入工作台
折叠
所有分类 我的工作台
展开

七色云彩之大话西游(二)

qyj133 qyj133 2021-03-12 08:49:18
步骤1 步骤1
项目来源
projectImage

七色云彩之大话西游作品原型来自经典创客项目雷电云。

项目结合经典电影大话西游,对雷电云进行改造和再创造。

《大话西游》中紫霞说,“我的意中人是盖世英雄,终有一天他会驾着七彩祥云来娶我。”

df社区相关项目连接:https://mc.dfrobot.com.cn/thread-15019-1-1.html

projectImage
projectImage
步骤2 步骤2
原项目介绍

原项目为自己的第一个版本,本次对原项目进行升级改造,大话西游的主题不变。

原项目连接:https://makelog.dfrobot.com.cn/article-309727.html

原项目名字有误,哈哈。项目名称不变:七色云彩之大话西游

原项目实现的功能:

1、OLED显示从网络获取的时间,显示室内温湿度。

2、人体靠近RGB灯带点亮并变色,MP3开始播放,离开后灯灭MP3停止。

步骤3 步骤3
新作品改造过程及说明
材料清单 材料清单
1x
esp8266
1x
OLED液晶屏
1x
人体感应传感器
1x
温度传感器
1x
mini mp3 player
1x
tf卡
1x
开关
1x
升压模块
1x
3.7V锂电池
1x
充放电模块
4x
rgb灯

一、经典画面,自己画不出来。第一版使用相框,这次用亚克力!

projectImage

二、底座3D打印

projectImage

三、电路连接

projectImage

四、程序编写

上一版本使用mixly图形化,这次使用arduino IDE

代码 代码
	                    					#include <SimpleTimer.h>
#include <Adafruit_NeoPixel.h>
#include <SoftwareSerial.h>
#include <ESP8266WiFi.h>
#include <ESP8266_Seniverse.h>
#include <U8g2lib.h>
#include <NTPClient.h> 
#include <WiFiUdp.h>
#include <WiFiManager.h> 
#include "DFRobotDFPlayerMini.h"
#include <OneWire.h>
#include <DallasTemperature.h>

//DS18B20
#define ONE_WIRE_BUS 0
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

// weather
const String weathers[] = {"晴", "晴", "晴", "晴", "多云", "晴间多云", "晴间多云", "大部多云", "大部多云", "阴",
                           "阵雨", "雷阵雨", "雷雨冰雹", "小雨", "中雨", "大雨", "暴雨", "大暴雨", "特大暴雨",
                           "冻雨", "雨夹雪", "阵雪", "小雪", "中雪", "大雪", "暴雪", "浮尘", "扬沙", "沙尘暴",
                           "强沙暴", "雾", "霾", "风", "大风", "飓风", "热带风暴", "龙卷风", "冷", "热", "未知"
                          };

String reqUserKey = "SZqaZCxwRELNhQnDI";// 私钥
String reqLocation = "baiyin";// 城市
String reqUnit = "c";// 摄氏/华氏

int8_t timeZone = 8;
const PROGMEM char *ntpServer = "ntp1.aliyun.com";

WeatherNow weatherNow;
Forecast forecast;
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "ntp1.aliyun.com", 60 * 60 * 8, 30 * 60 * 1000);
String weekDays[7]={"Sunday", "Monday", "Tuesday","Wednesday", "Thursday", "Friday", "Saturday"};
//Month names
String months[12]={"January", "February", "March", "April","May", "June", "July", "August", "September", "October", "November", "December"};


SimpleTimer timer;

int tem;
String str1;
String str2;
unsigned long epochTime;
String formattedTime;
int currentHour;
int currentMinute;
int currentSecond;
String weekDay;
int monthDay;
int currentMonth;
String currentMonthName;
int currentYear;
String currentDate;
String currentTimer;


U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE);
Adafruit_NeoPixel rgb_display_15 = Adafruit_NeoPixel(4,15,NEO_GRB + NEO_KHZ800);
SoftwareSerial mySerial(12,13);
DFRobotDFPlayerMini myPlayer;



// 连接WiFi
void connectWiFi() {
  // 建立WiFiManager对象
  WiFiManager wifiManager;
  // 自动连接WiFi。以下语句的参数是连接ESP8266时的WiFi名称
  wifiManager.autoConnect("AutoConnectAP");
}

void timeSet(){
//    timeClient.update();
    //获取时间戳
  epochTime = timeClient.getEpochTime();
    //转化为当前时间
  formattedTime = timeClient.getFormattedTime();
  currentHour = timeClient.getHours();
  currentMinute = timeClient.getMinutes();
  currentSecond = timeClient.getSeconds();
  weekDay = weekDays[timeClient.getDay()];
  struct tm *ptm = gmtime ((time_t *)&epochTime);
  monthDay = ptm->tm_mday;
  currentMonth = ptm->tm_mon+1;
  currentMonthName = months[currentMonth-1];
  currentYear = ptm->tm_year+1900;
  currentDate = String(currentYear) + "-" + String(currentMonth) + "-" + String(monthDay);
  currentTimer = String(currentHour) + "-" + String(currentMinute) + "-" + String(currentSecond);
}



void Simple_timer_1() {
  sensors.requestTemperatures();
  tem = sensors.getTempCByIndex(0);

  timeSet();// 调用时间
  u8g2.firstPage();
  do
  {
    page1();
  }while(u8g2.nextPage());
}

void page1() {
  u8g2.setCursor(5,5);
  u8g2.print(currentDate + "   " + currentTimer);
  u8g2.setCursor(5,20);
  u8g2.print(weekDay + " " + String("Tem:") + String(tem) + String("℃"));
  u8g2.setCursor(5,38);
  u8g2.print(str1);
  u8g2.setCursor(5,53);
  u8g2.print(str2);
}

uint32_t Wheel(byte WheelPos){
  if(WheelPos < 85){
    return rgb_display_15.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  }
  else if(WheelPos < 170){
    WheelPos -= 85;
    return rgb_display_15.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  }
  else{
    WheelPos -= 170;return rgb_display_15.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}

void Simple_timer_2() {
  if (!digitalRead(14)) {
    for(int RGB_RAINBOW_i = 0; RGB_RAINBOW_i < rgb_display_15.numPixels(); RGB_RAINBOW_i++){
      rgb_display_15.setPixelColor(RGB_RAINBOW_i, Wheel(((RGB_RAINBOW_i * 256 / rgb_display_15.numPixels()) + (random(30, 150))) & 255));
    }
    rgb_display_15.show();

  } else {
    for (int i = 1; i <= 4; i = i + (1)) {
      rgb_display_15.setPixelColor((i)-1, 0x000000);
      rgb_display_15.show();
      delay(100);
    }

  }
}

void setup() {
  Serial.begin(9600);
  u8g2.setI2CAddress(0x3C*2);
  u8g2.begin();
  u8g2.enableUTF8Print();
  u8g2.clearBuffer();
  u8g2.setFont(u8g2_font_wqy12_t_gb2312);
  u8g2.setFontPosTop();
  u8g2.sendBuffer();
  
  rgb_display_15.begin();
  mySerial.begin(9600);
  myPlayer.begin(mySerial);

  connectWiFi();// 连接wifi
  // 配置心知天气请求信息
  weatherNow.config(reqUserKey, reqLocation, reqUnit);
  forecast.config(reqUserKey, reqLocation, reqUnit);
  str1 = "天气信息更新中";
  str2 = "......";
  
  timeClient.begin();
  timeClient.update();

  myPlayer.volume(30);

  //u8g2.enableUTF8Print();
  tem = 0;
  sensors.begin();
  timer.setInterval(1000L, Simple_timer_1);

  pinMode(14, INPUT);
  pinMode(2, INPUT);
  timer.setInterval(10000L, Simple_timer_2);
  
}

void loop() {
  if (digitalRead(14)) {
    if (digitalRead(2)) {
      myPlayer.next();
      for(int RGB_RAINBOW_i = 0; RGB_RAINBOW_i < rgb_display_15.numPixels(); RGB_RAINBOW_i++){
        rgb_display_15.setPixelColor(RGB_RAINBOW_i, Wheel(((RGB_RAINBOW_i * 256 / rgb_display_15.numPixels()) + (random(30, 150))) & 255));
      }
      rgb_display_15.show();
      delay(100);

    }

  }

  timer.run();

  weatherOpen();

}

void weatherOpen(){//天气  
  if (weatherNow.update() && forecast.update()) { // 更新天气信息
    //今天的天气、温度
    str1 = "今日:" + weathers[weatherNow.getWeatherCode()] + " " + weatherNow.getDegree() + "  " + forecast.getLow(0) + "/" + forecast.getHigh(0) + "℃";
    //明天的天气、温度范围
    str2 = "明日:" + weathers[forecast.getDayCode(1)] + " " + forecast.getLow(1) + "至" + forecast.getHigh(1) + "℃";
    //后天的天气、温度范围
    //str3 = weathers[forecast.getDayCode(2)] + forecast.getLow(2) + "至" + forecast.getHigh(2) + "℃";
    timeClient.update();
  } else {// 更新失败

  }  
}
	                    				
步骤4 步骤4
成品介绍与展示
projectImage
projectImage
projectImage
步骤5 步骤5
总结

新项目实现的功能:

1、OLED显示从网络获取的时间,星期,天气预报(今日实时天气和温度,今日最高温和最低温,明日天气,明日最高和最低气温)。

2、人体靠近RGB灯带点亮并变色,MP3开始播放,离开后灯灭MP3停止。

与原项目相比,重点使用亚克力+3D打印,使得外形更加美观、更加有意境;其次,通过代码实现了mixly图形化没有的天气预报功能。

雷电云+大话西游,经典+经典,希望自己的作品没有辜负经典。

致敬经典!

怀念达叔!

projectImage
Makelog作者原创文章,未经授权禁止转载。
2
0
评论
[[c.user_name]] [[c.create_time]]
[[c.parent_comment.count]]
|
[[c.comment_content]]