查看: 72|回复: 3
打印 上一主题 下一主题

为什么我的会报错啊?求大神解答

[复制链接]

该用户从未签到

跳转到指定楼层
楼主
发表于 2019-9-26 13:33 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
#include
#include
#include
#include
#define DEBUG_ON

const char ssid[] = "*";? ?? ???// Your network SSID name here
const char pass[] = "*";? ?? ???// Your network password here
unsigned long timeZone = 1.0;? ?// Change this value to your local timezone (in my case +1 for Amsterdam)

// Change the colors here if you want.
// Check for reference: https://github.com/FastLED/FastLED/wiki/Pixel-reference#predefined-colors-list
// You can also set the colors with RGB values, for example red:
// CRGB colorHour = CRGB(255, 0, 0);
CRGB colorHour = CRGB::Red;
CRGB colorMinute = CRGB::Green;
CRGB colorSecond = CRGB::Blue;
CRGB colorHourMinute = CRGB::Yellow;
CRGB colorHourSecond = CRGB::Magenta;
CRGB colorMinuteSecond = CRGB::Cyan;
CRGB colorAll = CRGB::White;

// Set this to true if you want the hour LED to move between hours (if set to false the hour LED will only move every hour)
#define USE_LED_MOVE_BETWEEN_HOURS true

// Cutoff times for day / night brightness.
#define USE_NIGHTCUTOFF false? ?// Enable/Disable night brightness
#define MORNINGCUTOFF 8? ?? ?? ?// When does daybrightness begin?? ?8am
#define NIGHTCUTOFF 20? ?? ?? ? // When does nightbrightness begin? 10pm
#define NIGHTBRIGHTNESS 20? ?? ?// Brightness level from 0 (off) to 255 (full brightness)

ESP8266WiFiMulti wifiMulti;? ?? ?? ?? ?? ?? ?? ?
WiFiUDP UDP;? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?
IPAddress timeServerIP;? ?? ?? ?? ?? ?? ?? ?? ?
const char* NTPServerName = "time.nist.gov";? ?
const int NTP_PACKET_SIZE = 48;? ?? ?? ?? ?? ???
byte NTPBuffer[NTP_PACKET_SIZE];? ?? ?? ?? ?? ?

unsigned long intervalNTP = 5 * 60000; // Request NTP time every 5 minutes
unsigned long prevNTP = 0;
unsigned long lastNTPResponse = millis();
uint32_t timeUNIX = 0;
unsigned long prevActualTime = 0;

#define LEAP_YEAR(Y) ( ((1970+Y)>0) && !((1970+Y)%4) && ( ((1970+Y)%100) || !((1970+Y)%400) ) )
static const uint8_t monthDays[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

#define NUM_LEDS 60? ???
#define DATA_PIN D6;
CRGB LEDs[NUM_LEDS];

struct DateTime {
??int??year;
??byte month;
??byte day;
??byte hour;
??byte minute;
??byte second;
??byte dayofweek;
};

DateTime currentDateTime;

void setup() {

??FastLED.delay(3000);
??FastLED.addLeds(LEDs, NUM_LEDS);??

??Serial.begin(115200);? ?? ?? ?
??delay(10);
??Serial.println("\r\n");

??startWiFi();
??startUDP();

??if(!WiFi.hostByName(NTPServerName, timeServerIP)) {
? ? Serial.println("DNS lookup failed. Rebooting.");
? ? Serial.flush();
? ? ESP.reset();
??}
??Serial.print("Time server IP:\t");
??Serial.println(timeServerIP);

??Serial.println("\r\nSending NTP request ...");
??sendNTPpacket(timeServerIP);??
}

void loop() {
??unsigned long currentMillis = millis();

??if (currentMillis - prevNTP > intervalNTP) { // If a minute has passed since last NTP request
? ? prevNTP = currentMillis;
? ? Serial.println("\r\nSending NTP request ...");
? ? sendNTPpacket(timeServerIP);? ?? ?? ?? ?? ?// Send an NTP request
??}

??uint32_t time = getTime();? ?? ?? ?? ?? ?? ? // Check if an NTP response has arrived and get the (UNIX) time
??if (time) {? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? // If a new timestamp has been received
? ? timeUNIX = time;
? ? Serial.print("NTP response:\t");
? ? Serial.println(timeUNIX);
? ? lastNTPResponse = currentMillis;
??} else if ((currentMillis - lastNTPResponse) > 3600000) {
? ? Serial.println("More than 1 hour since last NTP response. Rebooting.");
? ? Serial.flush();
? ? ESP.reset();
??}

??uint32_t actualTime = timeUNIX + (currentMillis - lastNTPResponse)/1000;
??if (actualTime != prevActualTime && timeUNIX != 0) { // If a second has passed since last update
? ? prevActualTime = actualTime;
? ? convertTime(actualTime);

? ? for (int i=0; i
? ?? ?LEDs[i] = CRGB::Black;

? ? int second = getLEDMinuteOrSecond(currentDateTime.second);
? ? int minute = getLEDMinuteOrSecond(currentDateTime.minute);
? ? int hour = getLEDHour(currentDateTime.hour, currentDateTime.minute);

? ? // Set "Hands"
? ? LEDs[second] = colorSecond;
? ? LEDs[minute] = colorMinute;??
? ? LEDs[hour] = colorHour;??

? ? // Hour and min are on same spot
? ? if ( hour == minute)
? ?? ?LEDs[hour] = colorHourMinute;

? ? // Hour and sec are on same spot
? ? if ( hour == second)
? ?? ?LEDs[hour] = colorHourSecond;

? ? // Min and sec are on same spot
? ? if ( minute == second)
? ?? ?LEDs[minute] = colorMinuteSecond;

? ? // All are on same spot
? ? if ( minute == second && minute == hour)
? ?? ?LEDs[minute] = colorAll;

? ? if ( night() && USE_NIGHTCUTOFF == true )
? ?? ?FastLED.setBrightness (NIGHTBRIGHTNESS);

? ? FastLED.show();
??}??
}

byte getLEDHour(byte hours, byte minutes) {
??if (hours > 12)
? ? hours = hours - 12;

??byte hourLED;
??if (hours <= 5)
? ? hourLED = (hours * 5) + 30;
??else
? ? hourLED = (hours * 5) - 30;

??if (USE_LED_MOVE_BETWEEN_HOURS == true) {
? ? if? ?? ???(minutes >= 12 && minutes < 24) {
? ?? ?hourLED += 1;
? ? } else if (minutes >= 24 && minutes < 36) {
? ?? ?hourLED += 2;
? ? } else if (minutes >= 36 && minutes < 48) {
? ?? ?hourLED += 3;
? ? } else if (minutes >= 48) {
? ?? ?hourLED += 4;
? ? }
??}

??return hourLED;??
}

byte getLEDMinuteOrSecond(byte minuteOrSecond) {
??if (minuteOrSecond < 30)
? ? return minuteOrSecond + 30;
??else
? ? return minuteOrSecond - 30;
}

void startWiFi() {
??wifiMulti.addAP(ssid, pass);? ?

??Serial.println("Connecting");
??byte i = 0;
??while (wifiMulti.run() != WL_CONNECTED) {??
? ? delay(250);
? ? Serial.print('.');
? ? LEDs[i++] = CRGB::Green;
? ? FastLED.show();? ?
??}
??Serial.println("\r\n");
??Serial.print("Connected to ");
??Serial.println(WiFi.SSID());? ?? ?? ?? ?
??Serial.print("IP address:\t");
??Serial.print(WiFi.localIP());? ?? ?? ?? ?
??Serial.println("\r\n");
}

void startUDP() {
??Serial.println("Starting UDP");
??UDP.begin(123);? ?? ?? ?? ?? ?? ?? ?? ???// Start listening for UDP messages on port 123
??Serial.print("Local port:\t");
??Serial.println(UDP.localPort());
??Serial.println();
}

uint32_t getTime() {
??if (UDP.parsePacket() == 0) { // If there's no response (yet)
? ? return 0;
??}
??UDP.read(NTPBuffer, NTP_PACKET_SIZE); // read the packet into the buffer
??// Combine the 4 timestamp bytes into one 32-bit number
??uint32_t NTPTime = (NTPBuffer[40] << 24) | (NTPBuffer[41] << 16) | (NTPBuffer[42] << 8) | NTPBuffer[43];
??// Convert NTP time to a UNIX timestamp:
??// Unix time starts on Jan 1 1970. That's 2208988800 seconds in NTP time:
??const uint32_t seventyYears = 2208988800UL;
??// subtract seventy years:
??uint32_t UNIXTime = NTPTime - seventyYears;
??return UNIXTime;
}

void sendNTPpacket(IPAddress& address) {
??memset(NTPBuffer, 0, NTP_PACKET_SIZE);??// set all bytes in the buffer to 0
??// Initialize values needed to form NTP request
??NTPBuffer[0] = 0b11100011;? ?// LI, Version, Mode
??// send a packet requesting a timestamp:
??UDP.beginPacket(address, 123); // NTP requests are to port 123
??UDP.write(NTPBuffer, NTP_PACKET_SIZE);
??UDP.endPacket();
}

void convertTime(uint32_t time) {
??// Correct time zone
??time += (3600 * timeZone);

??currentDateTime.second = time % 60;
??currentDateTime.minute = time / 60 % 60;
??currentDateTime.hour? ?= time / 3600 % 24;
??time??/= 60;??// To minutes
??time??/= 60;??// To hours
??time??/= 24;??// To days
??currentDateTime.dayofweek = ((time + 4) % 7) + 1;
??int year = 0;
??int days = 0;
??while ((unsigned)(days += (LEAP_YEAR(year) ? 366 : 365)) <= time) {
? ? year++;
??}
??days -= LEAP_YEAR(year) ? 366 : 365;
??time??-= days; // To days in this year, starting at 0??
??days = 0;
??byte month = 0;
??byte monthLength = 0;
??for (month = 0; month < 12; month++) {
? ? if (month == 1) { // February
? ?? ?if (LEAP_YEAR(year)) {
? ?? ???monthLength = 29;
? ?? ?} else {
? ?? ???monthLength = 28;
? ?? ?}
? ? } else {
? ?? ?monthLength = monthDays[month];
? ? }

? ? if (time >= monthLength) {
? ?? ?time -= monthLength;
? ? } else {
? ?? ?break;
? ? }
??}

??currentDateTime.day = time + 1;
??currentDateTime.year = year + 1970;
??currentDateTime.month = month + 1;??

??// Correct European Summer time
??if (summerTime()) {
? ? currentDateTime.hour += 1;
??}

#ifdef DEBUG_ON
??Serial.print(currentDateTime.year);
??Serial.print(" ");
??Serial.print(currentDateTime.month);
??Serial.print(" ");
??Serial.print(currentDateTime.day);
??Serial.print(" ");
??Serial.print(currentDateTime.hour);
??Serial.print(" ");
??Serial.print(currentDateTime.minute);
??Serial.print(" ");
??Serial.print(currentDateTime.second);
??Serial.print(" day of week: ");
??Serial.print(currentDateTime.dayofweek);
??Serial.print(" summer time: ");
??Serial.print(summerTime());
??Serial.print(" night time: ");
??Serial.print(night());??
??Serial.println();
#endif??
}

boolean summerTime() {

??if (currentDateTime.month < 3 || currentDateTime.month > 10) return false;??// No summer time in Jan, Feb, Nov, Dec
??if (currentDateTime.month > 3 && currentDateTime.month < 10) return true;? ?// Summer time in Apr, May, Jun, Jul, Aug, Sep
??if (currentDateTime.month == 3 && (currentDateTime.hour + 24 * currentDateTime.day) >= (3 +??24 * (31 - (5 * currentDateTime.year / 4 + 4) % 7)) || currentDateTime.month == 10 && (currentDateTime.hour + 24 * currentDateTime.day) < (3 +??24 * (31 - (5 * currentDateTime.year / 4 + 1) % 7)))
??return true;
? ? else
??return false;
}

boolean night() {

??if (currentDateTime.hour >= NIGHTCUTOFF && currentDateTime.hour <= MORNINGCUTOFF)
? ? return true;? ?
}
  • TA的每日心情
    奋斗
    2019-9-27 08:47
  • 签到天数: 97 天

    [LV.6]常住居民II

    沙发
    发表于 2019-9-26 15:18 | 只看该作者
    你光把程序贴出来,啥也没说,报错是报了什么也不知道,谁能给你回答!!!!

    该用户从未签到

    板凳
    ?楼主| 发表于 2019-9-27 11:17 | 只看该作者
    秋缘 发表于 2019-9-26 15:18
    你光把程序贴出来,啥也没说,报错是报了什么也不知道,谁能给你回答!!!! ...

    对不起,我第一次玩,以为会没人回我。不好意思。Arduino:1.8.10 (Windows 10), 开发板:"Generic ESP8266 Module, 80 MHz, Flash, Disabled, All SSL ciphers (most compatible), ck, 26 MHz, 40MHz, DOUT (compatible), 512K (no SPIFFS), 2, nonos-sdk 2.2.1 (legacy), v2 Lower Memory, Disabled, None, Only Sketch, 115200"

    In file included from C:\Users\???????????\Documents\Arduino\libraries\FastLED/bitswap.h:4:0,

    ? ?? ?? ?? ?? ???from C:\arduino\led\led.ino:1:

    C:\Users\???????????\Documents\Arduino\libraries\FastLED/FastLED.h:14:21: note: #pragma message: FastLED version 3.003.002

    #? ? pragma message "FastLED version 3.003.002"

    ? ?? ?? ?? ?? ?? ?? ?^

    In file included from C:\Users\???????????\Documents\Arduino\libraries\FastLED/FastLED.h:65:0,

    ? ?? ?? ?? ?? ???from C:\Users\???????????\Documents\Arduino\libraries\FastLED/bitswap.h:4,

    ? ?? ?? ?? ?? ???from C:\arduino\led\led.ino:1:

    C:\Users\???????????\Documents\Arduino\libraries\FastLED/fastspi.h:130:23: note: #pragma message: No hardware SPI pins defined.??All SPI access will default to bitbanged output

    #? ?? ?pragma message "No hardware SPI pins defined.??All SPI access will default to bitbanged output"

    ? ?? ?? ?? ?? ?? ?? ???^

    C:\arduino\led\led.ino: In function 'void setup()':

    led:125:18: error: 'D6' was not declared in this scope

    #define DATA_PIN D6;

    ? ?? ?? ?? ?? ?? ?^

    C:\arduino\led\led.ino:161:28: note: in expansion of macro 'DATA_PIN'

    ? ?FastLED.addLeds(LEDs, NUM_LEDS);??

    ? ?? ?? ?? ?? ?? ?? ?? ?? ? ^

    led:161:11: error: parse error in template argument list

    ? ?FastLED.addLeds(LEDs, NUM_LEDS);??

    ? ?? ?? ???^

    led:125:20: error: statement cannot resolve address of overloaded function

    #define DATA_PIN D6;

    ? ?? ?? ?? ?? ?? ???^

    C:\arduino\led\led.ino:161:28: note: in expansion of macro 'DATA_PIN'

    ? ?FastLED.addLeds(LEDs, NUM_LEDS);??

    ? ?? ?? ?? ?? ?? ?? ?? ?? ? ^

    led:161:36: error: expected primary-expression before ',' token

    ? ?FastLED.addLeds(LEDs, NUM_LEDS);??

    ? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?^

    "bitswap.h" 对应多个库
    已使用: C:\Users\花吃了那女孩\Documents\Arduino\libraries\FastLED
    "ESP8266WiFi.h" 对应多个库
    已使用: C:\Users\花吃了那女孩\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2\libraries\ESP8266WiFi
    exit status 1
    'D6' was not declared in this scope

    下载 http://arduino.esp8266.com/stable/package_esp8266com_index.json 时出错
    下载 https://downloads.arduino.cc/packages/package_index.json 时出错

    在文件 -> 首选项开启
    “编译过程中显示详细输出”选项
    这份报告会包含更多信息。

    该用户从未签到

    地板
    ?楼主| 发表于 2019-9-27 11:20 | 只看该作者
    秋缘 发表于 2019-9-26 15:18
    你光把程序贴出来,啥也没说,报错是报了什么也不知道,谁能给你回答!!!! ...

    我是直接贴错误信息吗,可以加个微信吗,我微信号huachilnanvhai
    您需要登录后才可以回帖 登录 | 立即注册 ?

    本版积分规则

    热门推荐

    关于温湿度传感器在LCD显示上的问题
    关于温湿度传感器在LCD显
    我建立了一个程序,想要将dht11传感器得到的数据显示在LCD1602上,但是LCD显的都是乱
    【原创】全球最小口袋3D打印机mini one直播教程贴
    【原创】全球最小口袋3D打
    最近闲得蛋疼,没事搞个掌上3D打印机,先放效果图吧。 搞了半天,终于能正常打印,
    【Arduino】108种传感器模块系列实验(74)--- 4位LED数码管模块
    【Arduino】108种传感器模
    37款传感器与模块的提法,在网络上广泛流传,其实Arduino能够兼容的传感器模块肯定是
    (开源)ESP8266改装小风扇,app远程控制+天猫精灵控制
    (开源)ESP8266改装小风
    材料准备 [*]USB风扇一个 [*]ESP8266一块 [*]3.3继电器一块 拆解风扇 第一次,没有
    基于机器视觉的智能分拣机械臂
    基于机器视觉的智能分拣机
    本作品是一个基于机器视觉的智能机械臂操作平台,其采用atmega32单片机作为主控制系统
    Copyright ???2015-2016??Arduino中文社区??Powered by?Discuz! ??( 蜀ICP备14017632号-3 )
    快速回复 返回顶部 返回列表