/* * http://code.google.com/p/arduino-seven-segment/ * * This is a demo of the seven segment library * that shows how to set single segments * * 2018-11-30 Modified to demonstrate METP0000_lib.h * by Tony Wills */ #include // Pin definitions #define N_SCK 4 #define SI 5 #define BUSY 10 #define CS 8 #define FEATURE_COUNT 2 // Number of times to try each feature #define DIGIT_COUNT 6 // Number of digits supported in screen #define WAIT 100 // Delay between frames // Initialise LCD library METP0000 lcd(N_SCK, SI, BUSY, CS); void setup() { // Set display driver lcd.begin(6, 1); } // Turn all segments on and off void onAndOff() { for (int t = 0; t < FEATURE_COUNT; t++){ // Turn all known segments on lcd.home(); for (int d =0; d < DIGIT_COUNT; d++) { lcd.setSegment((d << 12) + 0x777); } delay(WAIT * 5); // Turn all known segments off lcd.clear(); delay(WAIT * 5); } } // Do spin animation void spin() {int segmentBarsData[7] = {0x400, 0x040, 0x010, 0x200, 0x001, 0x004, 0x100}; // 7 segment bars a to g for (int t = 0; t < FEATURE_COUNT; t++){ for (int s = 0; s < 6; s++){ // Turn on specific segments for (int d = 0; d < DIGIT_COUNT; d++) lcd.setSegment((d << 12) + segmentBarsData[s]); delay(WAIT); // Turn the segments back off for (int d = 0; d < DIGIT_COUNT; d++) lcd.clearSegment((d << 12) + segmentBarsData[s]); } } } // Animate horizontal segments void horizontalBars() { // Segment array for horizontal bars int horizontalBarsData[3] = {0x400, 0x100, 0x200}; // 7 segments a, g, d for (int t = 0; t < FEATURE_COUNT; t++){ // Draw bars for (int i = 0; i < 3; i++){ for (int d = 0; d < DIGIT_COUNT; d++) lcd.setSegment((d << 12) + horizontalBarsData[i]); delay(WAIT); } // Clear bars for (int i = 0; i < 3; i++){ for (int d = 0; d < DIGIT_COUNT; d++) lcd.clearSegment((d << 12) + horizontalBarsData[i]); delay(WAIT); } } } // Animate vertical segments void verticalBars(){ for (int t = 0; t < FEATURE_COUNT; t++){ // Draw bars for (int d = 0; d < DIGIT_COUNT; d++){ lcd.setSegment((d << 12) + 0x004); // segment f lcd.setSegment((d << 12) + 0x001); // segment e delay(WAIT); lcd.setSegment((d << 12) + 0x040); // segment b lcd.setSegment((d << 12) + 0x010); // segment c delay(WAIT); } // Clear bars for (int d = 0; d < DIGIT_COUNT; d++){ lcd.clearSegment((d << 12) + 0x004); lcd.clearSegment((d << 12) + 0x001); delay(WAIT); lcd.clearSegment((d << 12) + 0x040); lcd.clearSegment((d << 12) + 0x010); delay(WAIT); } } } // Print some text void printText(){ const char* message[6] = { "This", "is", "Some", "Cool", "LCD", "SHIT" }; for (int t = 0; t < FEATURE_COUNT; t++){ for (int m = 0; m < 6; m++){ lcd.print(message[m]);lcd.print(" "); delay(WAIT * 10); lcd.home(); } } lcd.clear(); } // Scroll some text void scrollingText(){ char buf[] = " Sometimes you have to scroll to get the message across... "; for (char* p = buf; p < buf + strlen(buf); p++){ lcd.print(p); delay(WAIT * 2); lcd.home(); } lcd.clear(); } // Animate some zeroes void printAnimation(){ const char* message[9] = { ".", "o", "0", "()", "( )", "( )", "POP", "----", "" }; for (int t = 0; t < FEATURE_COUNT; t++){ for (int m = 0; m < 9; m++){ lcd.print(message[m]); lcd.home(); delay(WAIT * 5); } } lcd.clear(); } // Toggle random segments on and off void randomSegments(){ /*for (int t = 0; t < 100; t++){ int segment = random(32); lcd.setSegment(segment, !lcd.getSegment(segment)); lcd.display(); delay(WAIT); }*/ lcd.clear(); } void loop(){ randomSegments(); onAndOff(); spin(); horizontalBars(); verticalBars(); printText(); scrollingText(); printAnimation(); randomSegments(); }