0% found this document useful (0 votes)
178 views

Codigo Prol+peller

This document contains Arduino code for an analog clock project using LEDs to display the time. It defines pin assignments for 16 LEDs, sets the initial time, and includes functions to clear the display, draw the hour, minute and second hands, and update the display in the main loop based on the elapsed time. The code uses microsecond delays to control the LED brightness and animation speed.

Uploaded by

Boris PQ
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
178 views

Codigo Prol+peller

This document contains Arduino code for an analog clock project using LEDs to display the time. It defines pin assignments for 16 LEDs, sets the initial time, and includes functions to clear the display, draw the hour, minute and second hands, and update the display in the main loop based on the elapsed time. The code uses microsecond delays to control the LED brightness and animation speed.

Uploaded by

Boris PQ
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 13

compnentes----------------

Arduino NANO: LINK eBay


LEDs: LINK eBay
7.4V LiPo: LINK eBay
Resistors: LINK eBay
Sliding switch: LINK eBay
A3144 hall switch: LINK eBay
Proto PCB: LINK eBay
.................................................

// hobbyprojects
// ArduinoNanoPropellerLEDAnalogClock20190403A

int LED1 = 2;
int LED2 = 3;
int LED3 = 4;
int LED4 = 5;
int LED5 = 6;
int LED6 = 7;
int LED7 = 8;
int LED8 = 9;
int LED9 = 10;
int LED10 = 11;
int LED11 = 12;
int LED12 = A1;
int LED13 = A2;
int LED14 = A3;
int LED15 = A4;
int LED16 = A5;

int sensorPin = A0;

unsigned int n,ADCvalue,propeller_posn;


unsigned long previousTime = 0;

byte hours = 12; // set hours


byte minutes = 15; // set minutes
byte seconds = 00; // set seconds

int val;

void setup()
{
pinMode(LED1,OUTPUT);
pinMode(LED2,OUTPUT);
pinMode(LED3,OUTPUT);
pinMode(LED4,OUTPUT);
pinMode(LED5,OUTPUT);
pinMode(LED6,OUTPUT);
pinMode(LED7,OUTPUT);
pinMode(LED8,OUTPUT);
pinMode(LED9,OUTPUT);
pinMode(LED10,OUTPUT);
pinMode(LED11,OUTPUT);
pinMode(LED12,OUTPUT);
pinMode(LED13,OUTPUT);
pinMode(LED14,OUTPUT);
pinMode(LED15,OUTPUT);
pinMode(LED16,OUTPUT);

pinMode(sensorPin,INPUT_PULLUP);

if(hours == 12)
hours = 0;
}

void loop()
{
val = digitalRead(sensorPin);

while (val == LOW)


{
val = digitalRead(sensorPin);
}

if (millis() >= (previousTime))


{
previousTime = previousTime + 1000;
seconds = seconds+1;
if (seconds == 60)
{
seconds = 0;
minutes = minutes+1;
}
if (minutes == 60)
{
minutes = 0;
hours = hours+1;
}
if (hours == 12)
{
hours = 0;
}
}

propeller_posn=30;
n=0;

while(n < 60)


{

drawMinuteMarker();

if ((propeller_posn==0) || (propeller_posn==5) || (propeller_posn==10) ||


(propeller_posn==15) || (propeller_posn==20) || (propeller_posn==25) ||
(propeller_posn==30) || (propeller_posn==35) || (propeller_posn==40) ||
(propeller_posn==45) || (propeller_posn==50) || (propeller_posn==55))
drawHourMarker();

if ((propeller_posn==0) || (propeller_posn==15) || (propeller_posn==30) ||


(propeller_posn==45))
drawQuarterMarker();

if((propeller_posn == hours*5) || (( propeller_posn == 0 ) && (hours == 0)))


drawHoursHand();
if(propeller_posn == minutes)
drawMinutesHand();

if(propeller_posn == seconds)
drawSecondsHand();

delayMicroseconds(140); // for LED pixel width (change the value according


to motor speed. Increase for low speed, decrease for high speed motor)

displayClear();

drawInner_Circle();

delayMicroseconds(600); // for the gap between LED pixels/minutes markers


(change the value according to motor speed. Increase for low speed, decrease for
high speed motor)

n++;
propeller_posn++;
if(propeller_posn == 60)
propeller_posn=0;
}

val = digitalRead(sensorPin);

while (val == HIGH)


{
val = digitalRead(sensorPin);
}
}

//=========================

void displayClear()
{
digitalWrite(LED1,LOW);
digitalWrite(LED2,LOW);
digitalWrite(LED3,LOW);
digitalWrite(LED4,LOW);
digitalWrite(LED5,LOW);
digitalWrite(LED6,LOW);
digitalWrite(LED7,LOW);
digitalWrite(LED8,LOW);
digitalWrite(LED9,LOW);
digitalWrite(LED10,LOW);
digitalWrite(LED11,LOW);
digitalWrite(LED12,LOW);
digitalWrite(LED13,LOW);
digitalWrite(LED14,LOW);
digitalWrite(LED15,LOW);
digitalWrite(LED16,LOW);
}

void drawMinuteMarker()
{
digitalWrite(LED16,HIGH);
}

void drawHourMarker()
{
digitalWrite(LED15,HIGH);
digitalWrite(LED14,HIGH);
}

void drawQuarterMarker()
{
digitalWrite(LED13,HIGH);
digitalWrite(LED12,HIGH);
}

void drawHoursHand()
{
digitalWrite(LED1,HIGH);
digitalWrite(LED2,HIGH);
digitalWrite(LED3,HIGH);
digitalWrite(LED4,HIGH);
digitalWrite(LED5,HIGH);
digitalWrite(LED6,HIGH);
digitalWrite(LED7,HIGH);
}

void drawMinutesHand()
{
digitalWrite(LED1,HIGH);
digitalWrite(LED2,HIGH);
digitalWrite(LED3,HIGH);
digitalWrite(LED4,HIGH);
digitalWrite(LED5,HIGH);
digitalWrite(LED6,HIGH);
digitalWrite(LED7,HIGH);
digitalWrite(LED8,HIGH);
digitalWrite(LED9,HIGH);
}

void drawSecondsHand()
{
digitalWrite(LED1,HIGH);
digitalWrite(LED2,HIGH);
digitalWrite(LED3,HIGH);
digitalWrite(LED4,HIGH);
digitalWrite(LED5,HIGH);
digitalWrite(LED6,HIGH);
digitalWrite(LED7,HIGH);
digitalWrite(LED8,HIGH);
digitalWrite(LED9,HIGH);
digitalWrite(LED10,HIGH);
digitalWrite(LED11,HIGH);
}

void drawInner_Circle()
{
digitalWrite(LED1,HIGH);
delayMicroseconds(30);
digitalWrite(LED1,LOW);
}
///////////////////////////////////////////////////////////////////////////////////
/////////////////////777
// hobbyprojects
// 10-02-2019 Arduino_NANO_Propeller_LED_Analog_Clock

unsigned int i,n,k,d,y;


unsigned long previousTime = 0;

byte hours = 12; // start time


byte minutes = 15;
byte seconds = 00;

int val;

void setup()
{
DDRD = 0xFE;
DDRB = 0xFF;
DDRC = 0xFE;
PORTC = 0x01;
PORTD = 0x03;
PORTB = 0x00;

if(hours == 12)
hours = 0;
}

void loop()
{
while(bit_is_clear(PINC, 0))
{
}
if (millis() >= (previousTime))
{
previousTime = previousTime + 1000;
seconds = seconds +1;
if (seconds == 60)
{
seconds = 0;
minutes = minutes +1;
}
if (minutes == 60)
{
minutes = 0;
hours = hours +1;
}
if (hours == 12)
{
hours = 0;
}
}
k=30;
n=0;
while(n < 60)
{
PORTC |= (1<<5);
if ((k==0) || (k==5) || (k==10) || (k==15) || (k==20) || (k==25) || (k==30) ||
(k==35) || (k==40) || (k==45) || (k==50) || (k==55))
{
PORTC |= (1<<4);
PORTC |= (1<<3);
}
if ((k==0) || (k==15) || (k==30) || (k==45))
{
PORTC |= (1<<2);
PORTC |= (1<<1);
}
if((k == hours*5) || (( k == 0 ) && (hours == 0)))
{
PORTD |= (1<<2);
PORTD |= (1<<3);
PORTD |= (1<<4);
PORTD |= (1<<5);
PORTD |= (1<<6);
PORTD |= (1<<7);
PORTB |= (1<<0);
}
if(k == minutes)
{
PORTD |= (1<<2);
PORTD |= (1<<3);
PORTD |= (1<<4);
PORTD |= (1<<5);
PORTD |= (1<<6);
PORTD |= (1<<7);
PORTB |= (1<<0);
PORTB |= (1<<1);
PORTB |= (1<<2);
}
if(k == seconds)
{
PORTD |= (1<<2);
PORTD |= (1<<3);
PORTD |= (1<<4);
PORTD |= (1<<5);
PORTD |= (1<<6);
PORTD |= (1<<7);
PORTB |= (1<<0);
PORTB |= (1<<1);
PORTB |= (1<<2);
PORTB |= (1<<3);
PORTB |= (1<<4);
}
delayMicroseconds(140);
PORTD = 0x03;
PORTB = 0x00;
PORTC = 0x01;
PORTD |= (1<<2);
delayMicroseconds(30);
PORTD &= ~(1<<2);
delayMicroseconds(600);
n++;
k++;
if(k == 60)
k=0;
}
while(bit_is_set(PINC, 0))
{
}
}
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
////////
// hobbyprojects
// 16-05-2019 PropellerClockRpmBatteryStatusDisplay

unsigned int x,j,n,k,d,ADCvalue,nm,dl;


unsigned long previousTime,rpm,tc,to = 0;
long v;
byte hours = 12; // set Hours
byte minutes = 15; // set minutes
byte seconds = 00; // set seconds
int i,m,f,f1,val = 0;
byte a,c;
char s;
const PROGMEM unsigned char
data[]={0x3f,0x23,0x23,0x3f,0x01,0x13,0x3f,0x03,0x2f,0x2b,0x2b,0x3b,0x2b,0x2b,0x2b,
0x3f,0x39,0x09,0x09,0x3f,0x3b,0x2b,0x2b,0x2f,0x3f,0x2b,0x2b,0x2f,0x21,0x27,0x29,0x3
1,0x3f,0x2b,0x2b,0x3f,0x3b,0x2b,0x2b,0x3f,0x00,0x00,0x15,0x00,0x01,0x01,0x3f,0x29,0
x2d,0x13,0x01,0x3f,0x29,0x29,0x11,0x01,0x3f,0x11,0x09,0x11,0x3f,0x39,0x05,0x03,0x05
,0x39,0x1F,0x11,0x11,0x00,0x1F,0x01,0x01,0x01,0x1f,0x11,0x11,0x1F,0x1F,0x11,0x11,0x
00,0x1F,0x04,0x0A,0x11};
void setup()
{
DDRD = 0xF8;
DDRB = 0xFF;
DDRC = 0xFE;
PORTC = 0x01;
PORTD = 0x07;
PORTB = 0x00;
if(hours == 12)
hours = 0;
attachInterrupt(0, usdl, RISING);
}
void loop()
{
while(m == 0)
{
while(bit_is_clear(PIND, 2))
{
}
k=45;
n=0;
while(n < 60)
{
ADCvalue = analogRead(A7);
if(ADCvalue < 500)
{
minutes = k;
seconds = 0;
}

ADCvalue = analogRead(A6);
if(ADCvalue < 500)
{
hours = k/5;
seconds = 0;
}
PORTC |= (1<<5);
if ((k==0) || (k==5) || (k==10) || (k==15) || (k==20) || (k==25) || (k==30) ||
(k==35) || (k==40) || (k==45) || (k==50) || (k==55))
{
PORTC |= (1<<4);
PORTC |= (1<<3);
}
if ((k==0) || (k==15) || (k==30) || (k==45))
{
PORTC |= (1<<2);
PORTC |= (1<<1);
}
if(k == hours*5 - 1)
PORTD |= (1<<7);
if((k == hours*5) || (( k == 0 ) && (hours == 0)))
{
PORTB |= (1<<5);
PORTD |= (1<<3);
PORTD |= (1<<4);
PORTD |= (1<<5);
PORTD |= (1<<6);
PORTD |= (1<<7);
PORTB |= (1<<0);
}
if(k == hours*5 + 1)
PORTD |= (1<<7);
if((k == 59) && (hours*5 == 0))
PORTD |= (1<<7);
if(k == minutes-1)
PORTB |= (1<<1);
if(k == minutes)
{
PORTB |= (1<<5);
PORTD |= (1<<3);
PORTD |= (1<<4);
PORTD |= (1<<5);
PORTD |= (1<<6);
PORTD |= (1<<7);
PORTB |= (1<<0);
PORTB |= (1<<1);
PORTB |= (1<<2);
}
if(k == minutes+1)
PORTB |= (1<<1);
if((k == 0) && (minutes == 59))
PORTB |= (1<<1);
if((k == 59) && (minutes == 0))
PORTB |= (1<<1);
if(k == seconds-1)
PORTB |= (1<<3);
if(k == seconds)
{
PORTB |= (1<<5);
PORTD |= (1<<3);
PORTD |= (1<<4);
PORTD |= (1<<5);
PORTD |= (1<<6);
PORTD |= (1<<7);
PORTB |= (1<<0);
PORTB |= (1<<1);
PORTB |= (1<<2);
PORTB |= (1<<3);
PORTB |= (1<<4);

}
if(k == seconds+1)
PORTB |= (1<<3);
if((k == 0) && (seconds == 59))
PORTB |= (1<<3);
if((k == 59) && (seconds == 0))
PORTB |= (1<<3);
delayMicroseconds(dl);
PORTD = 0x07;
PORTB = 0x00;
PORTC = 0x01;
PORTB |= (1<<5);
delayMicroseconds(dl/50);
PORTB &= ~(1<<5);
delayMicroseconds(dl*4);
n++;
k++;
if(k == 60)
k=0;
}
while(bit_is_set(PIND, 2))
{
}
}
while(m == 1)
{
while(bit_is_clear(PIND, 2))
{
}
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
delay(2);
ADCSRA |= _BV(ADSC);
while (bit_is_set(ADCSRA,ADSC));
v = ADCL;
v |= ADCH<<8;
v = 1125300L / v;
nm = v/1000;
nm = nm%10;
nD();
delayMicroseconds(dl*4);
PORTC = 0x03;
delayMicroseconds(dl);
PORTC = 0x01;
delayMicroseconds(dl*6);
nm = v/100;
nm = nm%10;
nD();
delayMicroseconds(dl*2);
nm = v/10;
nm = nm%10;
nD();
delayMicroseconds(dl*2);
i = 0;
while(i < 5)
{
PORTC = (pgm_read_byte(&(data+61)[i]));
delayMicroseconds(dl);
PORTC = 0x01;
delayMicroseconds(dl*2);
i++;
}
i = 0;
while(i < 10)
{
delayMicroseconds(dl);
i++;
}
rpm = (100000000/tc)*60;
nm = rpm/100000;
nm = nm%10;
if(nm !=0)
nD();
delayMicroseconds(dl*2);
nm = rpm/10000;
nm = nm%10;
nD();
delayMicroseconds(dl*2);
nm = rpm/1000;
nm = nm%10;
nD();
delayMicroseconds(dl*2);
nm = rpm/100;
nm = nm%10;
nD();
delayMicroseconds(dl*2);
i = 0;
while(i < 17)
{
PORTC = (pgm_read_byte(&(data+44)[i]));
delayMicroseconds(dl);
PORTC = 0x01;
delayMicroseconds(dl*2);
i++;
}
while(i < 50)
{
delayMicroseconds(dl);
i++;
}
nm = seconds;
nm = nm%10;
nmDB();
delayMicroseconds(dl*2);
nm = seconds/10;
nm = nm%10;
x=4;
nmDB2();
delayMicroseconds(dl*2);
nm = 10;
x=3;
nmDB2();
delayMicroseconds(dl*2);
nm = minutes;
nm = nm%10;
x=2;
nmDB2();
delayMicroseconds(dl*2);
nm = minutes/10;
nm = nm%10;
x=1;
nmDB2();
delayMicroseconds(dl*2);
nm = 10;
x=0;
nmDB2();
delayMicroseconds(dl*2);
nm = hours;
if(nm == 0)
nm = 12;
nm = nm%10;
nmDB();
delayMicroseconds(dl*2);
nm = hours;
if(nm == 0)
nm = 12;
nm=nm/10;
nm = nm%10;
nmDB();
while(bit_is_set(PIND, 2))
{
}
}
}
void nD()
{
j=nm*4;
i = 0;
while(i < 4)
{
PORTC = (pgm_read_byte(&(data+j)[i]));
delayMicroseconds(dl);
PORTC = 0x01;
delayMicroseconds(dl*2);
i++;
}
}
void nmDB2()
{
j=nm*4;
x = x*4;
i = 3;
while(i >= 0)
{
c = (pgm_read_byte(&(data+j)[i]));
s=0;
for(a = 0; a < 8; a++){
s <<= 1;
s |= c & 1;
c >>= 1;
}
s >>= 1;
PORTC = s;
c = (pgm_read_byte(&(data+66+x)[i]));
s=0;
for(a = 0; a < 8; a++){
s <<= 1;
s |= c & 1;
c >>= 1;
}
PORTB = s >>= 3;
PORTB &= ~(1<<5);
delayMicroseconds(dl);
PORTC = 0x01;
PORTB = 0x00;
PORTD = 0x04;
delayMicroseconds(dl*2);
i--;
}
}
void nmDB()
{
j=nm*4;
i = 3;
while(i >= 0)
{
c = (pgm_read_byte(&(data+j)[i]));
s=0;
for(a = 0; a < 8; a++){
s <<= 1;
s |= c & 1;
c >>= 1;
}
s >>= 1;
PORTC = s;
delayMicroseconds(dl);
PORTC = 0x01;
delayMicroseconds(dl*2);
i--;
}
}
void usdl()
{
f = 0;
n = 0;
tc = micros()-to;
to = micros();
f = 1;
if(m == 0)
dl = tc/410;
else
dl = tc/400;
if (millis() >= (previousTime))
{
previousTime = previousTime + 1000;
seconds = seconds+1;
if (seconds == 60)
{
seconds = 0;
minutes = minutes+1;
}
if (minutes == 60)
{
minutes = 0;
hours = hours+1;
}
if (hours == 12)
{
hours = 0;
}
}
if(bit_is_clear(PINC, 0))
m = 1;
else
m = 0;
}

You might also like