Difference between revisions of "5 Display numbers on Seven Segment Display"
(Created page with "Category:Arduino Tutorials 680px") |
|||
Line 1: | Line 1: | ||
[[Category:Arduino Tutorials]] | [[Category:Arduino Tutorials]] | ||
[[File:Arduino Display Numbers on Seven Segment Display.JPG|680px]] | [[File:Arduino Display Numbers on Seven Segment Display.JPG|680px]] | ||
+ | ==Code== | ||
+ | <syntaxhighlight> | ||
+ | /* | ||
+ | Display 0 to 9 on 7Segment Display. | ||
+ | */ | ||
+ | |||
+ | // Pin 13 has an LED connected on most Arduino boards. | ||
+ | // give it a name: | ||
+ | int a = 2; | ||
+ | int b = 3; | ||
+ | int c = 4; | ||
+ | int d = 5; | ||
+ | int e = 6; | ||
+ | int f = 7; | ||
+ | int g = 8; | ||
+ | // the setup routine runs once when you press reset: | ||
+ | void setup() { | ||
+ | // initialize the digital pin as an output. | ||
+ | pinMode(a, OUTPUT); | ||
+ | pinMode(b, OUTPUT); | ||
+ | pinMode(c, OUTPUT); | ||
+ | pinMode(d, OUTPUT); | ||
+ | pinMode(e, OUTPUT); | ||
+ | pinMode(f, OUTPUT); | ||
+ | pinMode(g, OUTPUT); | ||
+ | } | ||
+ | // the loop routine runs over and over again forever: | ||
+ | void loop() { | ||
+ | //Disply 0 | ||
+ | digitalWrite(a, HIGH); | ||
+ | digitalWrite(b, HIGH); | ||
+ | digitalWrite(c, HIGH); | ||
+ | digitalWrite(d, HIGH); | ||
+ | digitalWrite(e, HIGH); | ||
+ | digitalWrite(f, HIGH); | ||
+ | digitalWrite(g, LOW); | ||
+ | delay(500); | ||
+ | //Disply 1 | ||
+ | digitalWrite(a, LOW); | ||
+ | digitalWrite(b, HIGH); | ||
+ | digitalWrite(c, HIGH); | ||
+ | digitalWrite(d, LOW); | ||
+ | digitalWrite(e, LOW); | ||
+ | digitalWrite(f, LOW); | ||
+ | digitalWrite(g, LOW); | ||
+ | delay(500); | ||
+ | //Disply 2 | ||
+ | digitalWrite(a, HIGH); | ||
+ | digitalWrite(b, HIGH); | ||
+ | digitalWrite(c, LOW); | ||
+ | digitalWrite(d, HIGH); | ||
+ | digitalWrite(e, HIGH); | ||
+ | digitalWrite(f, LOW); | ||
+ | digitalWrite(g, HIGH); | ||
+ | delay(500); | ||
+ | //Disply 3 | ||
+ | digitalWrite(a, HIGH); | ||
+ | digitalWrite(b, HIGH); | ||
+ | digitalWrite(c, HIGH); | ||
+ | digitalWrite(d, HIGH); | ||
+ | digitalWrite(e, LOW); | ||
+ | digitalWrite(f, LOW); | ||
+ | digitalWrite(g, HIGH); | ||
+ | delay(500); | ||
+ | //Disply 4 | ||
+ | digitalWrite(a, LOW); | ||
+ | digitalWrite(b, HIGH); | ||
+ | digitalWrite(c, HIGH); | ||
+ | digitalWrite(d, LOW); | ||
+ | digitalWrite(e, LOW); | ||
+ | digitalWrite(f, HIGH); | ||
+ | digitalWrite(g, HIGH); | ||
+ | delay(500); | ||
+ | //Disply 5 | ||
+ | |||
+ | digitalWrite(a, HIGH); | ||
+ | digitalWrite(b, LOW); | ||
+ | digitalWrite(c, HIGH); | ||
+ | digitalWrite(d, HIGH); | ||
+ | digitalWrite(e, LOW); | ||
+ | digitalWrite(f, HIGH); | ||
+ | digitalWrite(g, HIGH); | ||
+ | delay(500); | ||
+ | //Disply 6 | ||
+ | digitalWrite(a, HIGH); | ||
+ | digitalWrite(b, LOW); | ||
+ | digitalWrite(c, HIGH); | ||
+ | digitalWrite(d, HIGH); | ||
+ | digitalWrite(e, HIGH); | ||
+ | digitalWrite(f, HIGH); | ||
+ | digitalWrite(g, HIGH); | ||
+ | delay(500); | ||
+ | //Disply 7 | ||
+ | digitalWrite(a, HIGH); | ||
+ | digitalWrite(b, HIGH); | ||
+ | digitalWrite(c, HIGH); | ||
+ | digitalWrite(d, LOW); | ||
+ | digitalWrite(e, LOW); | ||
+ | digitalWrite(f, LOW); | ||
+ | digitalWrite(g, LOW); | ||
+ | delay(500); | ||
+ | //Disply 8 | ||
+ | digitalWrite(a, HIGH); | ||
+ | digitalWrite(b, HIGH); | ||
+ | digitalWrite(c, HIGH); | ||
+ | digitalWrite(d, HIGH); | ||
+ | digitalWrite(e, HIGH); | ||
+ | digitalWrite(f, HIGH); | ||
+ | digitalWrite(g, HIGH); | ||
+ | delay(500); | ||
+ | //Disply 9 | ||
+ | digitalWrite(a, HIGH); | ||
+ | digitalWrite(b, HIGH); | ||
+ | digitalWrite(c, HIGH); | ||
+ | digitalWrite(d, HIGH); | ||
+ | digitalWrite(e, LOW); | ||
+ | digitalWrite(f, HIGH); | ||
+ | digitalWrite(g, HIGH); | ||
+ | delay(500); | ||
+ | } | ||
+ | |||
+ | <syntaxhighlight> |
Revision as of 00:13, 13 September 2014
Code
/* Display 0 to 9 on 7Segment Display. */ // Pin 13 has an LED connected on most Arduino boards. // give it a name: int a = 2; int b = 3; int c = 4; int d = 5; int e = 6; int f = 7; int g = 8; // the setup routine runs once when you press reset: void setup() { // initialize the digital pin as an output. pinMode(a, OUTPUT); pinMode(b, OUTPUT); pinMode(c, OUTPUT); pinMode(d, OUTPUT); pinMode(e, OUTPUT); pinMode(f, OUTPUT); pinMode(g, OUTPUT); } // the loop routine runs over and over again forever: void loop() { //Disply 0 digitalWrite(a, HIGH); digitalWrite(b, HIGH); digitalWrite(c, HIGH); digitalWrite(d, HIGH); digitalWrite(e, HIGH); digitalWrite(f, HIGH); digitalWrite(g, LOW); delay(500); //Disply 1 digitalWrite(a, LOW); digitalWrite(b, HIGH); digitalWrite(c, HIGH); digitalWrite(d, LOW); digitalWrite(e, LOW); digitalWrite(f, LOW); digitalWrite(g, LOW); delay(500); //Disply 2 digitalWrite(a, HIGH); digitalWrite(b, HIGH); digitalWrite(c, LOW); digitalWrite(d, HIGH); digitalWrite(e, HIGH); digitalWrite(f, LOW); digitalWrite(g, HIGH); delay(500); //Disply 3 digitalWrite(a, HIGH); digitalWrite(b, HIGH); digitalWrite(c, HIGH); digitalWrite(d, HIGH); digitalWrite(e, LOW); digitalWrite(f, LOW); digitalWrite(g, HIGH); delay(500); //Disply 4 digitalWrite(a, LOW); digitalWrite(b, HIGH); digitalWrite(c, HIGH); digitalWrite(d, LOW); digitalWrite(e, LOW); digitalWrite(f, HIGH); digitalWrite(g, HIGH); delay(500); //Disply 5 digitalWrite(a, HIGH); digitalWrite(b, LOW); digitalWrite(c, HIGH); digitalWrite(d, HIGH); digitalWrite(e, LOW); digitalWrite(f, HIGH); digitalWrite(g, HIGH); delay(500); //Disply 6 digitalWrite(a, HIGH); digitalWrite(b, LOW); digitalWrite(c, HIGH); digitalWrite(d, HIGH); digitalWrite(e, HIGH); digitalWrite(f, HIGH); digitalWrite(g, HIGH); delay(500); //Disply 7 digitalWrite(a, HIGH); digitalWrite(b, HIGH); digitalWrite(c, HIGH); digitalWrite(d, LOW); digitalWrite(e, LOW); digitalWrite(f, LOW); digitalWrite(g, LOW); delay(500); //Disply 8 digitalWrite(a, HIGH); digitalWrite(b, HIGH); digitalWrite(c, HIGH); digitalWrite(d, HIGH); digitalWrite(e, HIGH); digitalWrite(f, HIGH); digitalWrite(g, HIGH); delay(500); //Disply 9 digitalWrite(a, HIGH); digitalWrite(b, HIGH); digitalWrite(c, HIGH); digitalWrite(d, HIGH); digitalWrite(e, LOW); digitalWrite(f, HIGH); digitalWrite(g, HIGH); delay(500); } <syntaxhighlight>