element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
element14's The Ben Heck Show
  • Challenges & Projects
  • element14 presents
  • element14's The Ben Heck Show
  • More
  • Cancel
element14's The Ben Heck Show
Forum attiny binary clock
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join element14's The Ben Heck Show to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 1 reply
  • Subscribers 29 subscribers
  • Views 442 views
  • Users 0 members are here
  • clock
  • binary
  • attiny
  • arduino
Related

attiny binary clock

atharvabenheckfan
atharvabenheckfan over 11 years ago

hi community an ben heck fans

i had just recieved my attinys in the mail

and decided to make a binary clock from it without shift registers

and thus i found this post : http://www.428industries.com/nerd-watch/

i tried to complile the code and it gave me a whole bunch of errors

  1. i needed a button library (solved)(i think)
  2. i need a clock library as clock.h
  3. i needed a Led library (provided) ( i guess thats the one)
  4. and this :

Time                Now( 8 /* hour */, 0 /* minutes */, 0 /* seconds */, false /* am */);

NerdWatch:119: error: 'Clock' does not name a type

NerdWatch.ino: In function 'void loop()':

NerdWatch:143: error: 'Now' was not declared in this scope

NerdWatch:145: error: 'class Button' has no member named 'Update'

NerdWatch:150: error: 'class Button' has no member named 'WasPressed'

Button.ino: In function 'void setup()':

Button:35: error: redefinition of 'void setup()'

NerdWatch:123: error: 'void setup()' previously defined here

Button.ino: In function 'void loop()':

Button:42: error: redefinition of 'void loop()'

NerdWatch:140: error: 'void loop()' previously defined here

here's the code:

//

// NerdWatch -- a simple PCB that displays the time in binary by flashing two LEDs.

//              The hour is first displayed using 4 bits, and then the position of the "big hand"

//              of the clock is displayed using the next 4 bits. The green LED indicates a binary 1,

//              and yellow indicates a binary zero. For instance, the time 6:50 would

//              be displayed using the following flashing pattern (Y = yellow, G = green):

//                   Y G G Y <pause> G Y G Y

//

// Written by Tony DeRose, April 2014

// (c) 428 Industries

//

#include <Button.h>

#include <Clock.h>

#include <LED.h>

#include <avr/power.h>

 

 

// Pin definitions

#define BUTTON_PIN              0

#define YELLOW_PIN              1

#define GREEN_PIN               2

 

 

// Delay definitions

#define BIT_DISPLAY_DELAY       500                     // Display a bit for this many millis

#define INTER_BIT_DELAY         100                     // Wait this many millis between bits

#define POST_DISPLAY_DELAY      500                     // Wait this many millis after displaying hours or minutes

 

 

LED                  OneLed(GREEN_PIN);

LED                  ZeroLed( YELLOW_PIN);

 

 

//

// A class to do serial single bit display using the two

// LEDs in a non-blocking fashion

//

class BitDisplayer {

public:

    typedef enum {

        OFF_STATE,

        DISPLAYING_BIT_STATE,

        BETWEEN_BITS_STATE,

        POST_DISPLAY_STATE,

    } DisplayerState;

 

 

    BitDisplayer() {}

   

    void SetValueToDisplay(uint8_t value) {

        _value = value;

    }

   

    void Start() {

        _state = BETWEEN_BITS_STATE;

        _bitNum = 3;

        _time = 0;

    }

   

    void Update() {

        switch (_state) {

            case OFF_STATE:

               // Do nothing

            break;

           

            case BETWEEN_BITS_STATE:

                if (millis() - _time > INTER_BIT_DELAY) {

                    // Display the next bit

                    if (_bitNum >= 0) {

                        uint8_t mask = 1 << _bitNum;

                        if (_value & mask) {

                            OneLed.SetIntensity(64);            // To save power

                        } else {

                            ZeroLed.SetIntensity(64);

                        }

                        _time = millis();

                        _bitNum--;

                        _state = DISPLAYING_BIT_STATE;

                    } else {

                        _state = POST_DISPLAY_STATE;

                        _time = millis();

                    }

                }

            break;

               

            case DISPLAYING_BIT_STATE:

                if (millis() - _time > BIT_DISPLAY_DELAY) {

                    _time = millis();

                    _state = BETWEEN_BITS_STATE;

                    OneLed.SetMode(LED::OFF);

                    ZeroLed.SetMode(LED::OFF);

                }

            break;

 

 

            case POST_DISPLAY_STATE:

                if (millis() - _time > POST_DISPLAY_DELAY) {

                    _state = OFF_STATE;

                }

            break;       

        }

    }

   

    bool IsDone() {

        return _state == OFF_STATE;

    }

   

private:

    int                   _bitNum;      // Which bit is currently being displayed

    DisplayerState        _state;       // The current state

    uint32_t              _time;        // Used for accurate non-blocking delays

    uint8_t               _value;       // The value to display

};

 

 

 

 

// States of the system

typedef enum {

    OFF_STATE,

    DISPLAYING_HOUR_STATE,

    DISPLAYING_MINUTE_STATE,

} StateType;

 

 

BitDisplayer         Displayer;

Clock                Now( 8 /* hour */, 0 /* minutes */, 0 /* seconds */, false /* am */);

StateType            State = OFF_STATE;

Button               TellTimeButton( BUTTON_PIN, false /* isAnalogPin */, true /* pressedWhenLow */);

 

 

void setup()

{

    // Configure for low power operation

    power_adc_disable();

   

    pinMode(YELLOW_PIN, OUTPUT);

    ZeroLed.SetIsOnWhenHigh(false);

    ZeroLed.SetMode(LED::OFF);

   

    pinMode(GREEN_PIN, OUTPUT);

    OneLed.SetIsOnWhenHigh(false);

    OneLed.SetMode(LED::OFF);

   

    pinMode(BUTTON_PIN, INPUT);

    digitalWrite( BUTTON_PIN, HIGH);              // Connect internal pull up resistor

}

 

 

void loop()

{

    Displayer.Update();

    Now.Update();

    OneLed.Update();

    TellTimeButton.Update();

    ZeroLed.Update();

   

    switch(State) {

        case OFF_STATE:

            if (TellTimeButton.WasPressed()) {

                ZeroLed.SetMode(LED::OFF);

                Displayer.SetValueToDisplay( Now.GetHours());

                Displayer.Start();

                State = DISPLAYING_HOUR_STATE;

            }

        break;

       

        case DISPLAYING_HOUR_STATE:

            if (Displayer.IsDone()) {

                // Round minutes off to nearest five minutes

                Displayer.SetValueToDisplay( (Now.GetMinutes() + 2)/5);

                Displayer.Start();

                State = DISPLAYING_MINUTE_STATE;

            }

        break;

 

 

        case DISPLAYING_MINUTE_STATE:

            if (Displayer.IsDone()) {

                State = OFF_STATE;

            }

       break;

    }

}

##########################################################

please help

  • Sign in to reply
  • Cancel
  • Former Member
    Former Member over 10 years ago

    Hi

    i made the same with attiny85 by the instructables tutorial

    look at this place:

    The Nerd Watch

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube