Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*****************************************************************
- PORT Command is used to change the state of pin i.e. On or OFF
- DDR is used to set the pinmode whether as input/output,
- thus DDR register instead of using pinMode().
- *****************************************************************/
- void setup()
- {
- DDRB = 0b00011111; //B0-B1(Set as output); DDR-Data Direvction Register is used to set the pin as input(0) or output(1)
- DDRD = 0b11111111; //D1-D7(Set as output)
- }
- void loop()
- {
- start();
- red();
- for (int i = 9; i >= 0; i--)
- {
- for ( int j = 9; j>=0; j--)
- {
- for (int del = 0; del < 15; del++)
- {
- disp(i, j,'r');
- }
- if(i==3 && j==0 ){
- yellow();
- }
- }
- }
- disp(0,0,'g');
- green();
- delay(5000);
- }
- void start()
- { int i = 2;
- while (i != 0)
- {
- if (i == 2)
- {
- PORTB = 0b00000010; //Turn ON B1-pin and other pins of port B are OFF.
- }
- if (i == 1)
- {
- PORTB = 0b00000001;
- }
- PORTD = 0b00000010;
- PORTD = ~PORTD;
- delay(100);
- PORTD = 0b00000110;
- PORTD = ~PORTD;
- delay(100);
- PORTD = 0b00001110;
- PORTD = ~PORTD;
- delay(100);
- PORTD = 0b00011110;
- PORTD = ~PORTD;
- delay(100);
- PORTD = 0b00111110;
- PORTD = ~PORTD;
- delay(100);
- PORTD = 0b01111110;
- PORTD = ~PORTD;
- delay(100);
- PORTD = 0b11111110;
- PORTD = ~PORTD;
- delay(200);
- PORTD = 0b01111110;
- PORTD = ~PORTD;
- delay(100);
- PORTD = 0b00111110;
- PORTD = ~PORTD;
- delay(100);
- PORTD = 0b00011110;
- delay(100);
- PORTD = 0b00001110;
- delay(100);
- PORTD = 0b00000110;
- delay(100);
- PORTD = 0b00000010;
- delay(100);
- PORTD = 0b00000000;
- delay(200);
- i--;
- }
- }
- void zero()
- {
- PORTD = 0b10000001;
- }
- void one()
- {
- PORTD = 0b00001100;
- PORTD = ~PORTD;
- }
- void two()
- {
- PORTD = 0b10110110;
- PORTD = ~PORTD;
- }
- void three()
- {
- PORTD = 0b10011110;
- PORTD = ~PORTD;
- }
- void four()
- {
- PORTD = 0b11001100;
- PORTD = ~PORTD;
- }
- void five()
- {
- PORTD = 0b11011010;
- PORTD = ~PORTD;
- }
- void six()
- {
- PORTD = 0b11111010;
- PORTD = ~PORTD;
- }
- void seven()
- {
- PORTD = 0b00001110;
- PORTD = ~PORTD;
- }
- void eight()
- {
- PORTD = 0b11111110;
- PORTD = ~PORTD;
- }
- void nine()
- {
- PORTD = 0b11011110;
- PORTD = ~PORTD;
- }
- void red(){
- PORTB = 0b00000100;
- }
- void yellow(){
- PORTB = 0b00001100;
- }
- void green(){
- PORTB = (PORTB|0b00010000)&0b00010011;
- }
- void digit1(int x)
- {
- PORTB = (PORTB|0b00000010)&0b11111110;
- switch (x) {
- case 1: one(); break;
- case 2: two(); break;
- case 3: three(); break;
- case 4: four(); break;
- case 5: five(); break;
- case 6: six(); break;
- case 7: seven(); break;
- case 8: eight(); break;
- case 9: nine(); break;
- case 10: zero(); break;
- case 0: zero(); break;
- }
- }
- void digit2(int x)
- {
- PORTB = (PORTB|0b00000001)&0b11111101;
- switch (x) {
- case 1: one(); break;
- case 2: two(); break;
- case 3: three(); break;
- case 4: four(); break;
- case 5: five(); break;
- case 6: six(); break;
- case 7: seven(); break;
- case 8: eight(); break;
- case 9: nine(); break;
- case 0: zero(); break;
- case 10: zero(); break;
- }
- }
- void disp(int i, int j,char x)
- {
- digit1(i);
- delay(10);
- digit2(j);
- delay(10);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement