极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 11322|回复: 5

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

[复制链接]
发表于 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_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 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[CLOCK_PIXELS];
uint32_t colors[MAX_PALETTES][4] =
  {
    {
      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[MAX_BUTTONS_INPUT];
int currentButtonValue[MAX_BUTTONS_INPUT];

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[pin] )
  {
    currentButtonValue[pin] = val;
    return val;
  }
   
  delay(DEBOUNCE_DELAY);
  
  val = digitalRead(pin);
  if( val != lastButtonValue[pin] )
  {
    currentButtonValue[pin] = val;
    return val;
  }
  
  currentButtonValue[pin] = lastButtonValue[pin];
  return lastButtonValue[pin];
}

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

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:}
回复 支持 反对

使用道具 举报

发表于 2015-6-25 23:54:43 | 显示全部楼层
LZ,不通过的话,难道没有出错提示么?

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

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

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

使用道具 举报

发表于 2015-6-26 21:29:25 | 显示全部楼层
                    电路图?
回复 支持 反对

使用道具 举报

发表于 2015-6-27 08:44:20 | 显示全部楼层
楼主id够硬的,还是老问题,原理图(或者接线图),软件算法。你用的ide版本以及编译出错信息,如果你用的库,把库贴上来。不要把大家想成对你这个作品充满好奇,知识储备足够,库和IDE用的也和你一样。
都做到了,也不一定能解决,如果不这么做,一定白问。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-4-26 01:30 , Processed in 0.040226 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表