Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- byte hexadecimalNumbers[16][7] = { { 0,0,0,0,0,0,1}, // = 0
- { 1,0,0,1,1,1,1 }, // = 1
- { 0,0,1,0,0,1,0 }, // = 2
- { 0,0,0,0,1,1,0 }, // = 3
- { 1,0,0,1,1,0,0 }, // = 4
- { 0,1,0,0,1,0,0 }, // = 5
- { 0,1,0,0,0,0,0 }, // = 6
- { 0,0,0,1,1,1,1 }, // = 7
- { 0,0,0,0,0,0,0 }, // = 8
- { 0,0,0,1,1,0,0 }, // = 9
- { 0,0,0,1,0,0,0 }, // = A
- { 0,0,0,0,0,0,0 }, // = B
- { 0,1,1,0,0,0,1 }, // = C
- { 0,0,0,0,0,0,1 }, // = D
- { 0,1,1,0,0,0,0 }, // = E
- { 0,1,1,1,0,0,0 } // = F
- };
- void setup() {
- pinMode(2, OUTPUT);
- pinMode(3, OUTPUT);
- pinMode(4, OUTPUT);
- pinMode(5, OUTPUT);
- pinMode(6, OUTPUT);
- pinMode(7, OUTPUT);
- pinMode(8, OUTPUT);
- pinMode(9, OUTPUT);
- pinMode(10, OUTPUT);
- pinMode(11, OUTPUT);
- pinMode(12, OUTPUT);
- digitalWrite(9, LOW);
- digitalWrite(10, LOW);
- digitalWrite(11, LOW);
- digitalWrite(12, LOW);
- Serial.begin(9600);
- }
- void sevenSegWrite(byte digit) {
- byte pin = 2;
- for (byte segCount = 0; segCount < 7; ++segCount) {
- digitalWrite(pin, hexadecimalNumbers[digit][segCount]);
- ++pin;
- }
- }
- void checkIfCorrectCommand(char firstCharacter){
- if(firstCharacter == "T"){
- numbersToDisplay();
- }
- else if(firstCharacter == "D"){
- timeOfDisplaying();
- }
- else if(firstCharacter == "B"){
- brightnessOfSegments();
- }
- else{
- Serial.println("Unknown command");
- }
- }
- void numbersToDisplay(){
- String numbersSequence = Serial.readString();
- if(numbersSequence.length() == 6){
- char characterToTest;
- for(int i = 0; i<6; i++){
- characterToTest = numbersSequence.charAt(i);
- if((characterToTest>='a' && characterToTest<='f') ||
- (characterToTest>='A' && characterToTest<='F') ||
- (characterToTest>='0' && characterToTest<='9')){
- //TO DO
- }
- else{
- Serial.println("Wrong sequence of characters");
- }
- }
- }
- }
- void timeOfDisplaying(){
- String time = Serial.readString();
- if(time.length() == 4){
- char characterToTest;
- for(int i = 0; i<4; i++){
- characterToTest = time.charAt(i);
- if((characterToTest>='0' && characterToTest<='9' && i!=0)
- || (characterToTest>='1' && characterToTest<='9' && i==0)){
- //TO DO
- }
- else{
- Serial.println("Wrong sequence of characters");
- }
- }
- }
- else{
- Serial.println("Too few characters");
- }
- }
- void brightnessOfSegments(){
- String brightness = Serial.readString();
- if(brightness.length() == 4){
- char characterToTest;
- for(int i = 0; i<4; i++){
- characterToTest = brightness.charAt(i);
- if(characterToTest>='0' && characterToTest<='2'){
- //TO DO
- }
- else{
- Serial.println("Wrong sequence of characters");
- }
- }
- }
- else{
- Serial.println("Too few characters");
- }
- }
- void loop() {
- if(Serial.available() > 0){
- for(int i=15; i>=0; i--){
- delay(1000);
- sevenSegWrite(i);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement