Introduction: Klocka

Picture of Klocka

En arduinoklocka

Step 1: Vad Vi Ska Göra!

Från början skulle vi göra en klocka med temperatur och luftfuktighets mätare. Men slutade med en klocka med en 7-segments display.

Här är vårt kretsschema med en RTH, som är en temperatur och luftfuktighets mätare. Saknas dock kod till den.

Step 2: Vad Som Behövdes

Saker vi hade med i vårt projekt

Arduino Uno Bread board + extra lång 4 st Tryckknapp PCB 6x6x12mm BCD Driver 4511B DIP-16 BCD-to-7-Segment LED Latch Decoder Drivers 4051B DIP-16 Single 8ch Analog Multiplexer/Demuliplexer LED display 7-Segment 10mm 4 siffror Sladdar i olika färger 220 ohm motstånd

Step 3: Kod

int hour=9;

int minute=29;

int firstpin=6;

int secondpin=7;

int thirdpin=8;

int fourthpin=9;

int prevmillis;

int interval=50; int second;

int firstanode=2;

int secondanode=3;

int thirdanode=4; int fourthanode=5;

void setup() {

pinMode(7, OUTPUT);

pinMode(2, OUTPUT);

pinMode(3, OUTPUT);

pinMode(4, OUTPUT);

pinMode(5, OUTPUT);

pinMode(6, OUTPUT);

pinMode(7, OUTPUT);

pinMode(8, OUTPUT);

pinMode(9, OUTPUT);

pinMode(A0, INPUT_PULLUP);

pinMode(A1, INPUT_PULLUP);

pinMode(A2, INPUT_PULLUP);

pinMode(A3, INPUT_PULLUP);

Serial.begin(9600); }

void loop() {

if ((millis() - prevmillis) >interval) { prevmillis = millis(); second ++;

if (second == 60) { second=0; minute++; }

if (minute==60){ minute=0; hour++; }

if(hour==24){ hour=0; } }//if interval

// if dig read(a0)==LOW //minute++ //id digr read a1==LOW //minute--

Displaytime (hour,minute); }//loop

//Displatbars (temp, hum);

//Kolla knappar, kolla därefter

void Displaytime( int hour_, int minute_) {

int digit2= hour_ % 10;

//entals siffran hour

int digit1= hour_ - digit2 * 10;

//tiotalsiffran hour

int digit4= minute_ % 10;

//entals siffran minute

int digit3= minute_ - digit4 * 10 ;

//tiotalsiffran minute

Serial.print(digit1);

Serial.print(digit2);

Serial.print(digit3);

Serial.println(digit4);

digitalWrite(firstanode, HIGH);

BCDwrite(digit1);

delay(20); digitalWrite (2, LOW);

digitalWrite(secondanode, HIGH);

BCDwrite(digit2);

delay(20);

digitalWrite (3, LOW);

digitalWrite(thirdanode, HIGH);

BCDwrite(digit3);

delay(20);

digitalWrite (4, LOW);

digitalWrite(fourthanode, HIGH);

BCDwrite(digit4);

delay(20);

digitalWrite (5, LOW); }

void BCDwrite (int number) //0-9

{

digitalWrite(firstpin, bitRead(number, 0));

digitalWrite(secondpin, bitRead(number, 1));

digitalWrite(thirdpin, bitRead(number, 2));

digitalWrite(fourthpin, bitRead(number, 3)); }

Step 4: Bilder

Picture of Bilder

Comments

Jan_Henrik (author)2014-05-28

Looks cool, but write it on english please :)

About This Instructable

456views

5favorites

License:

More by hannarydholm:Klocka
Add instructable to: