Last active
March 9, 2016 11:43
-
-
Save xerrni/fef8eeb1cb05505781cb to your computer and use it in GitHub Desktop.
Arduino kod v0.1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <LiquidCrystal.h> | |
int tab[4]={1,6,9,0},value=0,previousvalue=1; | |
int led = 13,novalue=1,zero=0; | |
//31 34 35 42 ++++++++++ | |
// 32 33 36 - 41 ------- | |
// the setup routine runs once when you press reset: | |
void setup() { | |
// initialize the digital pin as an output. | |
Serial.begin(9600); | |
pinMode(led, OUTPUT); | |
int w=31; | |
for(;w<=42;w++) | |
pinMode(w, OUTPUT); | |
} | |
void modulo(int number) | |
{ | |
int i=3,j=0; | |
novalue=1; | |
if(number < 0) number=0; | |
else if(number > 0) novalue=0; | |
for(;i>=0;i--) | |
{ | |
tab[i]=number%10; | |
number/=10; | |
} | |
for(i=0;i<4;i++){ | |
if(tab[i]!=0) break; | |
else tab[i]=10; | |
} | |
} | |
void _high() | |
{ | |
int w=31; | |
for(;w<=42;w++) | |
digitalWrite(w,HIGH); | |
} | |
void _display() | |
{ | |
static int numbers[10][11]={{0,1,1,0,0,1,1,1,0,1,0}, //0 | |
{0,0,0,0,0,1,0,0,0,1,0}, //1 | |
{0,1,0,0,0,1,1,1,0,0,1}, //2 | |
{0,1,0,0,0,1,0,1,0,1,1}, //3 | |
{0,0,1,0,0,1,0,0,0,1,1}, //4 | |
{0,1,1,0,0,0,0,1,0,1,1}, //5 | |
{0,1,1,0,0,0,1,1,0,1,1}, //6 | |
{0,1,0,0,0,1,0,0,0,1,0}, //7 | |
{0,1,1,0,0,1,1,1,0,1,1}, //8 | |
{0,1,1,0,0,1,0,1,0,1,1} //9 | |
}; | |
static int characters[2][11]={{0,1,1,0,0,0,1,1,0,0,1}, //E | |
{0,0,0,0,0,0,1,0,0,0,1} //r | |
}; | |
static int segment_pins[4]={31,34,35,42}; | |
int time = 1,i=0,j=1; | |
if(novalue==1) | |
{ | |
_high(); | |
digitalWrite(31,LOW); | |
for(;i<=10;i++) | |
if(characters[0][i] == 1) digitalWrite(31+i,LOW); | |
delay(time); | |
for(;j<4;j++) | |
{ | |
_high(); | |
digitalWrite(segment_pins[j],LOW); | |
for(i=0;i<=10;i++) | |
if(characters[1][i] == 1) digitalWrite(31+i,LOW); | |
delay(time); | |
} | |
} | |
else | |
{ | |
for(j=0;j<4;j++) | |
{ | |
if(tab[j]==10) continue; | |
_high(); | |
digitalWrite(segment_pins[j],LOW); | |
for(i=0;i<=10;i++) | |
if(numbers[tab[j]][i] == 1) digitalWrite(31+i,LOW); | |
delay(time); | |
} | |
} | |
} | |
// the loop routine runs over and over again forever: | |
void loop() { | |
_high(); | |
if (Serial.available()) | |
{ | |
value = Serial.parseInt(); | |
Serial.println(value); | |
modulo(value); | |
} | |
_display(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment