// seven segment
const byte numeral[10] = { B11111100, // 0
B01100000, // 1
B11011010, // 2
B11110010, // 3
B01100110, // 4
B10110110, // 5
B10111110, // 6
B11100000, // 7
B11111110, // 8
B11110110, // 9
};
const int segmentPins[8] = { 2, 11, 10, 5, 4, 3, 8, 9 }; //dp,g,f,e,d,c,b,a
void showdigit(int number) {
boolean isBitSet;
for (int segment = 1; segment < 8; segment++) {
isBitSet = bitRead(numeral[number], segment);
// isBitSet will be true if given bit is 1
digitalWrite(segmentPins[segment], isBitSet);
digitalWrite(segmentPins[0], HIGH);
}
}
void setup() {
for (int i = 0; i < 8; i++) {
pinMode(segmentPins[i], OUTPUT); // set segment and DP pins to output
}
}
void loop() {
for (int i = 0; i <= 9; i++) {
showdigit(i);
delay(1000);
}
}
/*
debounce
int SettledValue = LOW;
int previousButtonState = LOW;
long lastChangeTime = 0;
long debounceDelay = 0.5;
int buttonState;
void setup() {
// put your setup code here, to run once:
pinMode(4, INPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
buttonState = digitalRead(4);
if (buttonState != previousButtonState) {
lastChangeTime = millis();
}
if ((millis() - lastChangeTime) > debounceDelay) {
if (buttonState != SettledValue) {
SettledValue = buttonState;
if (SettledValue == HIGH) {
Serial.println("Button Pressed");
}
}
}
previousButtonState = SettledValue;
}
Button
void setup() {
pinMode(8,INPUT);
Serial.begin(9600);
}
void loop() {
int BSTATE= digitalRead(8);
if(BSTATE == HIGH){
Serial.println(("button bushed"));
}
}
KEYPAD
#include <Keypad.h>
const byte row = 4;
const byte col = 4;
char keys[row][col] = {{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'}, {'7', '8', '9', 'C'}, {'*', '0', '#', 'D'}
};
byte rowpin[row] = {9,8,7,6};
byte colpin[col] = {5,4,3,2};
Keypad coustomKeypad = Keypad(makeKeymap(keys),rowpin,colpin,row,col);
void setup() {
Serial.begin(9600);
}
void loop() {
char coustomKey = coustomKeypad.getKey();
if(coustomKey){
Serial.println(coustomKey);
}
}
*/