Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
10 views4 pages

Exp 4

The document contains two Arduino programs for controlling a seven-segment display. The first program increments or decrements a displayed number based on button presses, while the second program uses a TM1637 display library for the same functionality with improved button handling. Both programs include setup and loop functions to manage input and output operations effectively.

Uploaded by

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

Exp 4

The document contains two Arduino programs for controlling a seven-segment display. The first program increments or decrements a displayed number based on button presses, while the second program uses a TM1637 display library for the same functionality with improved button handling. Both programs include setup and loop functions to manage input and output operations effectively.

Uploaded by

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

Program:

const int a = 13;


const int b = 12;
const int c = 11;
const int d = 10;
const int e = 9;
const int f = 8;
const int g = 7;
int k = 0;
const int upPin = 2;
const int DownPin = 3;
int x = 0;
int upx = 0; //up
int upy = 0; //down
int downx = 0; //up
int downy = 0; //down
void setup() {
pinMode(a, OUTPUT);
pinMode(b, OUTPUT);
pinMode(c, OUTPUT);
pinMode(d, OUTPUT);
pinMode(e, OUTPUT);
pinMode(f, OUTPUT);
pinMode(g, OUTPUT);
pinMode( 2, INPUT);
pinMode( 3, INPUT);
segmentdigit(x);
}
void loop() {
upx = digitalRead(2);
downx = digitalRead(3);
checkupxButtonPress();
checkdownxButtonPress();
if( k ){
k = 0;
turnOff();
segmentdigit(x);
}
}
void checkupxButtonPress()
{
if (upx != upy) {
if (upx == LOW) {
k = 1;
x++;
if(x > 9) x =0 ;
} else {
}
delay(50);
}
upy = upx;
}
void checkdownxButtonPress()
{
if (downx != downy) {
if (downx == LOW) {
k = 1;
x--;
if( x < 0) x =9 ;
} else
delay(50);
}
downy = downx;
}
void segmentdigit(int digit)
{
if(digit!=1 && digit != 4)
digitalWrite(a,HIGH);

if(digit != 5 && digit != 6)


digitalWrite(b,HIGH);

if(digit !=2)
digitalWrite(c,HIGH);

if(digit != 1 && digit !=4 && digit !=7)


digitalWrite(d,HIGH);

if(digit == 2 || digit ==6 || digit == 8 || digit==0)


digitalWrite(e,HIGH);

if(digit != 1 && digit !=2 && digit!=3 && digit !=7)


digitalWrite(f,HIGH);
if (digit!=0 && digit!=1 && digit !=7)
digitalWrite(g,HIGH);
}
void turnOff()
{
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
}

CODE:

#include <TM1637Display.h>
const int buttonIncrement = 2;
const int buttonDecrement = 3;
const int CLK = 11; // Clock pin
const int DIO = 10; // Data pin
TM1637Display display(CLK, DIO);
int count = 0;

void setup() {
// Initialize buttons
pinMode(buttonIncrement, INPUT_PULLUP);
pinMode(buttonDecrement, INPUT_PULLUP);

// Initialize the display


display.setBrightness(0x0f); // Set the display to maximum brightness
}

void loop() {
// Check the increment button
if (digitalRead(buttonIncrement) == LOW) {
delay(200); // Debounce delay
count++;
}

// Check the decrement button


if (digitalRead(buttonDecrement) == LOW) {
delay(200); // Debounce delay
count--;
}

// Display the count


display.showNumberDec(count, true); // Display the number with leading zero
suppression
}

You might also like