玉皇大帝 发表于 2015-6-25 13:13:38

有关斐波那契时钟的代码编译不通过

本帖最后由 玉皇大帝 于 2015-6-25 13:16 编辑

源代码在此,求大神看看哪里有问题
#include <Wire.h>
#include "RTClib.h"
#include <Adafruit_NeoPixel.h>

#define STRIP_PIN 8
#define HOUR_PIN 3
#define MINUTE_PIN 4
#define BTN_PIN 5
#define SET_PIN 6
#define DEBOUNCE_DELAY 10
#define MAX_BUTTONS_INPUT 20
#define MAX_MODES 3
#define MAX_PALETTES 4
#define CLOCK_PIXELS 5

// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB   Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB   Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(10, STRIP_PIN, NEO_RGB + NEO_KHZ800);

byte bits;
uint32_t colors =
{
    {
      strip.Color(255,255,255),    // off
      strip.Color(255,10,10),// hours
      strip.Color(10,255,10),// minutes
      strip.Color(10,10,255) // both;
    },
    {
      strip.Color(255,255,255),    // off
      strip.Color(255,10,10),// hours
      strip.Color(248,202,0),// minutes
      strip.Color(10,10,255) // both;
    },
    {
      strip.Color(255,255,255),    // off
      strip.Color(228,101,43),// hours
      strip.Color(158,168,38),// minutes
      strip.Color(28,224,208) // both;
    },
    {
      strip.Color(255,255,255),    // off
      strip.Color(203,36,2),// hours
      strip.Color(184,220,60),// minutes
      strip.Color(53,35,93) // both;
    }
};

RTC_DS1307 rtc;

byte oldHours = 0;
byte oldMinutes = 0;

int lastButtonValue;
int currentButtonValue;

int mode = 0;
int palette = 0;

void setup()
{
// Initialize the strip and set all pixels to 'off'
strip.begin();
strip.show();

// Open serial comm with the PC
Serial.begin(9600);

Wire.begin();
rtc.begin();

if (! rtc.isrunning())
{
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}

// Make the random() function return unpredictable results
randomSeed(rtc.now().unixtime());

pinMode(HOUR_PIN, INPUT);
pinMode(MINUTE_PIN, INPUT);
pinMode(BTN_PIN, INPUT);
pinMode(SET_PIN, INPUT);

pinMode(13, OUTPUT);

for(int i=0;i<2;i++)
{
    digitalWrite(13, HIGH);
    delay(100);
    digitalWrite(13, LOW);
    delay(100);
}

}

void loop()
{
// 9:25
//setPixel(0, strip.Color(255,255,255));
//setPixel(1, strip.Color(255,10,10));
//setPixel(2, strip.Color(10,255,10));
//setPixel(3, strip.Color(10,10,255));
//setPixel(4, strip.Color(255,10,10));
//strip.show();
//return;

// Read buttons
int set_button = debounce(SET_PIN);
int hour_button = debounce(HOUR_PIN);
int minute_button = debounce(MINUTE_PIN);
int button = debounce(BTN_PIN);

if( set_button && hour_button && hasChanged(HOUR_PIN))
{
    DateTime fixTime = rtc.now();
    rtc.adjust( DateTime(fixTime.unixtime() + 3600) );
    displayCurrentTime();
}
else if( set_button && minute_button && hasChanged(MINUTE_PIN))
{
    DateTime fixTime = rtc.now();
    rtc.adjust( DateTime(
          fixTime.year(),
          fixTime.month(),
          fixTime.day(),
          fixTime.hour(),
          (fixTime.minute()+5)%60,
          fixTime.second()) );
         
    displayCurrentTime();
}
else if( hour_button && hasChanged(HOUR_PIN))
{
    palette = (palette+1)%MAX_PALETTES;
    oldHours = 99;
}
else if( button && hasChanged(BTN_PIN))
{
    mode = (mode+1)%MAX_MODES;
}

// Store buttons new values
resetButtonValues();
Serial.println(mode, DEC);
switch(mode)
{
    case 0:
      displayCurrentTime();
      break;
      
    case 1:
      oldHours = 99;
      rainbowCycle(20);
      break;
      
    case 2:
      oldHours = 99;
      rainbow(20);
      break;
}
}

int debounce(int pin)
{
int val = digitalRead(pin);
if( val == lastButtonValue )
{
    currentButtonValue = val;
    return val;
}
   
delay(DEBOUNCE_DELAY);

val = digitalRead(pin);
if( val != lastButtonValue )
{
    currentButtonValue = val;
    return val;
}

currentButtonValue = lastButtonValue;
return lastButtonValue;
}

boolean hasChanged(int pin)
{
return lastButtonValue != currentButtonValue;
}

void resetButtonValues()
{
for(int i=0; i<MAX_BUTTONS_INPUT; i++)
    lastButtonValue = currentButtonValue;
}

void displayCurrentTime()
{
DateTime now = rtc.now();
setTime(now.hour()%12, now.minute());
}

void setTime(byte hours, byte minutes)
{
if(oldHours == hours && oldMinutes/5 == minutes/5)
    return;
   
oldHours = hours;
oldMinutes = minutes;

for(int i=0; i<CLOCK_PIXELS; i++)
    bits

玉皇大帝 发表于 2015-6-25 13:21:01

自己顶!{:soso_e128:}

玉皇大帝 发表于 2015-6-25 18:20:55

难道就没有人能解答下么{:soso_e109:}

pumpitup 发表于 2015-6-25 23:54:43

LZ,不通过的话,难道没有出错提示么?

还有,你硬件搭建好了么?

还有,你程序是从无到有慢慢编出来的么?

如果上一条的答案为是,那你编一点就编译一下,不就知道是哪一步出错了么。

suoma 发表于 2015-6-26 21:29:25

                  电路图?

沧海笑1122 发表于 2015-6-27 08:44:20

楼主id够硬的,还是老问题,原理图(或者接线图),软件算法。你用的ide版本以及编译出错信息,如果你用的库,把库贴上来。不要把大家想成对你这个作品充满好奇,知识储备足够,库和IDE用的也和你一样。
都做到了,也不一定能解决,如果不这么做,一定白问。
页: [1]
查看完整版本: 有关斐波那契时钟的代码编译不通过