Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define P0 12
- #define P1 11
- #define P2 10
- #define P3 9
- #define P4 8
- #define P5 7
- #define P6 6
- #define LED 3
- #define LIGHTSEG0 digitalWrite(P0, HIGH)
- #define LIGHTSEG1 digitalWrite(P1, HIGH)
- #define LIGHTSEG2 digitalWrite(P2, HIGH)
- #define LIGHTSEG3 digitalWrite(P3, HIGH)
- #define LIGHTSEG4 digitalWrite(P4, HIGH)
- #define LIGHTSEG5 digitalWrite(P5, HIGH)
- #define LIGHTSEG6 digitalWrite(P6, HIGH)
- #define OFFSEG0 digitalWrite(P0, LOW)
- #define OFFSEG1 digitalWrite(P1, LOW)
- #define OFFSEG2 digitalWrite(P2, LOW)
- #define OFFSEG3 digitalWrite(P3, LOW)
- #define OFFSEG4 digitalWrite(P4, LOW)
- #define OFFSEG5 digitalWrite(P5, LOW)
- #define OFFSEG6 digitalWrite(P6, LOW)
- void printOne(){
- digitalWrite(P1, HIGH);
- digitalWrite(P2, HIGH);
- delay(1000);
- digitalWrite(P1, LOW);
- digitalWrite(P2, LOW);
- }
- void printTwo(){
- digitalWrite(P0, HIGH);
- digitalWrite(P1, HIGH);
- digitalWrite(P6, HIGH);
- digitalWrite(P4, HIGH);
- digitalWrite(P3, HIGH);
- delay(1000);
- digitalWrite(P0, LOW);
- digitalWrite(P1, LOW);
- digitalWrite(P6, LOW);
- digitalWrite(P4, LOW);
- digitalWrite(P3, LOW);
- }
- void printThree(){
- digitalWrite(P0, HIGH);
- digitalWrite(P1, HIGH);
- digitalWrite(P6, HIGH);
- digitalWrite(P2, HIGH);
- digitalWrite(P3, HIGH);
- delay(1000);
- digitalWrite(P0, LOW);
- digitalWrite(P1, LOW);
- digitalWrite(P6, LOW);
- digitalWrite(P2, LOW);
- digitalWrite(P3, LOW);
- }
- void printFour(){
- digitalWrite(P1, HIGH);
- digitalWrite(P5, HIGH);
- digitalWrite(P6, HIGH);
- digitalWrite(P2, HIGH);
- delay(1000);
- digitalWrite(P1, LOW);
- digitalWrite(P5, LOW);
- digitalWrite(P6, LOW);
- digitalWrite(P2, LOW);
- }
- void printFive(){
- digitalWrite(P0, HIGH);
- digitalWrite(P5, HIGH);
- digitalWrite(P6, HIGH);
- digitalWrite(P2, HIGH);
- digitalWrite(P3, HIGH);
- delay(1000);
- digitalWrite(P0, LOW);
- digitalWrite(P5, LOW);
- digitalWrite(P6, LOW);
- digitalWrite(P2, LOW);
- digitalWrite(P3, LOW);
- }
- void printSix(){
- digitalWrite(P0, HIGH);
- digitalWrite(P5, HIGH);
- digitalWrite(P6, HIGH);
- digitalWrite(P2, HIGH);
- digitalWrite(P3, HIGH);
- digitalWrite(P4, HIGH);
- delay(1000);
- digitalWrite(P0, LOW);
- digitalWrite(P5, LOW);
- digitalWrite(P6, LOW);
- digitalWrite(P2, LOW);
- digitalWrite(P3, LOW);
- digitalWrite(P4, LOW);
- }
- void printSeven(){
- LIGHTSEG0;
- LIGHTSEG1;
- LIGHTSEG2;
- delay(1000);
- OFFSEG0;
- OFFSEG1;
- OFFSEG2;
- }
- void printEight(){
- LIGHTSEG0;
- LIGHTSEG1;
- LIGHTSEG2;
- LIGHTSEG3;
- LIGHTSEG4;
- LIGHTSEG5;
- LIGHTSEG6;
- delay(1000);
- OFFSEG0;
- OFFSEG1;
- OFFSEG2;
- OFFSEG3;
- OFFSEG4;
- OFFSEG5;
- OFFSEG6;
- }
- void printNine(){
- LIGHTSEG0;
- LIGHTSEG1;
- LIGHTSEG2;
- LIGHTSEG3;
- LIGHTSEG5;
- LIGHTSEG6;
- delay(1000);
- OFFSEG0;
- OFFSEG1;
- OFFSEG2;
- OFFSEG3;
- OFFSEG5;
- OFFSEG6;
- }
- void printZero(){
- LIGHTSEG0;
- LIGHTSEG1;
- LIGHTSEG2;
- LIGHTSEG3;
- LIGHTSEG4;
- LIGHTSEG5;
- delay(1000);
- OFFSEG0;
- OFFSEG1;
- OFFSEG2;
- OFFSEG3;
- OFFSEG4;
- OFFSEG5;
- }
- void setup() {
- Serial.begin(9600);
- Serial.println("Initializing Pins...");
- pinMode(P0, OUTPUT);
- pinMode(P1, OUTPUT);
- pinMode(P2, OUTPUT);
- pinMode(P3, OUTPUT);
- pinMode(P4, OUTPUT);
- pinMode(P5, OUTPUT);
- pinMode(P6, OUTPUT);
- pinMode(LED , OUTPUT);
- delay(1000);
- }
- void loop() {
- int pot_val = analogRead(A2);
- int mp_val = map(pot_val, 1, 1023, 0, 9);
- if(pot_val < 100 || pot_val >800){
- digitalWrite(LED, HIGH);
- }
- else{
- digitalWrite(LED, LOW);
- }
- Serial.print("Potentiometer Value: ");
- Serial.println(pot_val);
- Serial.print("Mapped Value: ");
- Serial.println(mp_val);
- switch(mp_val){
- case 1:
- Serial.println("Printing 1");
- printOne();
- delay(1000);
- break;
- case 2:
- Serial.println("Printing 2");
- printTwo();
- delay(1000);
- break;
- case 3:
- Serial.println("Printing 3");
- printThree();
- delay(1000);
- break;
- case 4:
- Serial.println("Printing 4");
- printFour();
- delay(1000);
- break;
- case 5:
- Serial.println("Printing 5");
- printFive();
- delay(1000);
- break;
- case 6:
- Serial.println("Printing 6");
- printSix();
- delay(1000);
- break;
- case 7:
- Serial.println("Printing 7");
- printSeven();
- delay(1000);
- break;
- case 8:
- Serial.println("Printing 8");
- printEight();
- delay(1000);
- break;
- case 9:
- Serial.println("Printing 9");
- printNine();
- delay(1000);
- break;
- default:
- Serial.println("Printing 0");
- printZero();
- delay(1000);
- }
- Serial.println(" ");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement