//RECOMMENDED METHOD #2 //convenience method for updating both displays, whether //they be scrolling or static. This method should be //called more frequently than the desired scroll rate... // In fact, intended to be called every tight "loop" // // This method will update if // (a) displaystring is short (<8 non-scrolling) AND marked as changed // (b) displaystirng is long (>8 scrolling) AND marked as changed // (c) displaystring is long (>8)....passed off to updateDisplayScroll // to handle the scrolling of the display. void mizraith_HDSP2111::updateDisplays() { for(uint8_t i=0; i < NUMBER_OF_DISPLAYS; i++) { uint8_t displaynum = i+1; if(stringLengthChanged(displaynum)) { setDisplayStringAsNew(DISPLAY_DATA[i].TEXT , displaynum); } if( (DISPLAY_DATA[i].TEXT_LENGTH <=8) && (!DISPLAY_DATA[i].TEXT_CHANGED) ) { //NOTE: The following lines are "optional", as they may add //unnecessary extra traffic. However, by leaving the following //active, the display can 'auto-update' short strings without intervention DISPLAY_DATA[i].SCROLL_COMPLETE = false; writeDisplay(DISPLAY_DATA[i].TEXT, displaynum); } else if( (DISPLAY_DATA[i].TEXT_LENGTH <=8) && (DISPLAY_DATA[i].TEXT_CHANGED) ) { //refresh it DISPLAY_DATA[i].SCROLL_COMPLETE = false; writeDisplay(DISPLAY_DATA[i].TEXT, displaynum); } else if (DISPLAY_DATA[i].TEXT_LENGTH > 8) { updateDisplayScroll(displaynum); } DISPLAY_DATA[i].TEXT_CHANGED = false; } }
void SenseMeMatrixTwoClass::begin(void) { i2c_addr = 0x70; Wire.begin(); Wire.beginTransmission(i2c_addr); Wire.write(0x21); // turn on oscillator Wire.endTransmission(); blinkRate(HT16K33_BLINK_OFF); setBrightness(15); // max brightness clear(); writeDisplay(); }
/** * Routine for clearing out a display and it's associated * variables. Displaynum should * be 1/2 (matching the CE lines). Updates the * DISPLAYx_LAST_UPDATE counter, too. * */ void mizraith_HDSP2111::resetDisplay(uint8_t displaynum) { if( displaynum > NUMBER_OF_DISPLAYS) { return; } else { uint8_t displayindex = displaynum-1; DISPLAY_DATA[displayindex].LAST_UPDATE = millis(); DISPLAY_DATA[displayindex].TEXT = BLANK_STRING; DISPLAY_DATA[displayindex].TEXT_LENGTH = 8; DISPLAY_DATA[displayindex].SCROLL_POSITION = 0; DISPLAY_DATA[displayindex].SCROLL_COMPLETE = false; DISPLAY_DATA[displayindex].TEXT_CHANGED = false; writeDisplay(DISPLAY_DATA[displayindex].TEXT, displaynum); clearControlWord(displaynum); } }
void Ada7Seg::writeint(qint16 num) { quint16 res, absol; qint16 aux[4]; qint8 sign; int i; for (i = 0; i<4; i++) aux[i] = 0; if (num < 0) { absol = -num; sign = 1; } else { absol = num; sign = 0; } for (i=0;i<4;i++) { res = absol % 10; absol /= 10; aux[i] = numbertable[res]; if (!absol) break; } if (sign && i<3) { i++; aux[i] = 0x40; // minus sign } displaybuffer[0] = aux[3]; displaybuffer[1] = aux[2]; displaybuffer[3] = aux[1]; displaybuffer[4] = aux[0]; displaybuffer[2] = 0; //semi dot (:) off writeDisplay(4); }
void scrollDisplay(char *words) { char buffer[9]; int i = 0; while(words[i] != 0){ boolean blank = false; for (int j = 0; j<8; j++) { if ( !blank && words[i+j] == 0 ) { blank = true; } if ( blank ) { buffer[j] = ' '; } else { buffer[j] = words[i+j]; } } buffer[8]=0; writeDisplay(buffer); delay(200); i++; } }
/** * // argv[0] = display_write.c // argv[n] = '-s' // argv[n+1] = new speed // argv[m] = '-m' // argv[m+1] = 'blagh blagh' */ int main(int argc, char *argv[]) { int i, j, localCurrentChar, localCurrentColumn; int idString = 0; unsigned int speed = 500; int scrolling = 0; unsigned char buffer[32]; for(i = 0; i < 32; i++) buffer[i] = 0x00; unsigned int currentChar = 0, currentColumn = 0; for(j = LED_DISPLAY_NUM-1; j >= 0; j --) { i = (j == 0) ? 1 : 0; initDisplay(j, i); // channel j, master mode } //check arguments for(i = 1; i < argc; i++) { if(strcmp(argv[i], "-s") == 0) { speed = atoi(argv[i + 1]); if(speed < 0 || speed > 5000) { printf("Speed must be limited between 0 and 5000.\r\n"); return 1; } } if(strcmp(argv[i], "-m") == 0) { idString = i + 1; } } if(idString == 0) { printf("Usage: %s [-s speed] -m 'text string'\r\n", argv[0]); return 1; } scrolling = 1; while(scrolling) { localCurrentChar = currentChar; localCurrentColumn = currentColumn; // draw current display for(j = LED_DISPLAY_NUM - 1; j >= 0; j--) { // draw current frame for(i = 0; i < 32; i++) { if(localCurrentChar == 0 && localCurrentColumn == 0 && i == 31 && j == 0 && speed == 0) scrolling = 0; if(localCurrentChar >= 0 && localCurrentChar < strlen(argv[idString])) // to check it is not nonsense { buffer[31-i] = font_5x7[argv[idString][localCurrentChar] - 32][localCurrentColumn]; } else { buffer[31-i] = 0x00; } if(currentChar > (strlen(argv[idString]) + (6*LED_DISPLAY_NUM) + 1)) scrolling = 0; // dirty FILTHY hack if(localCurrentColumn == 0) { localCurrentColumn = 4; localCurrentChar -= 1; } else { localCurrentColumn -= 1; } } writeDisplay(j, buffer); // send text to display } // setup start points for next frame if(currentColumn == 4) { currentColumn = 0; currentChar += 1; } else { currentColumn += 1; } delay(speed); } return 0; }
/** * Given a preloaded string in DISPLAY1_STRING, * check against a counter and update whenever its * been more than DISPLAY1_SCROLL_DELAY long (ms) * Also uses DISPLAY1_SCROLL_POSITION as next * start point to display. You can reset the display * by setting this to zero. * * At end of string will set flag DISPLAY1_SCROLL_COMPLETE * * Why? So that we're not blocking operations like * the scrollDisplay() method. * * Params: * uint8_t displaynum either 1 or 2 for this purpose. * References: * char *DISPLAYx_STRING * uint8_t DISPLAYx_SCROLL_POSITION [0:stringlength-1] * uint16_t DISPLAYx_SCROLL_DELAY * boolean DISPLAYx_SCROLL_COMPLETE (sets to 1 at end of string and stops operation) */ void mizraith_HDSP2111::updateDisplayScroll(uint8_t displaynum) { char *text; char buffer[9]; unsigned long temp; boolean proceed = true; uint8_t scrollindex; uint8_t displayindex = displaynum - 1 ; if( displaynum > NUMBER_OF_DISPLAYS) { return; } if (DISPLAY_DATA[displayindex].SCROLL_COMPLETE) { return; } //setup display specific values scrollindex = DISPLAY_DATA[displayindex].SCROLL_POSITION; text = DISPLAY_DATA[displayindex].TEXT; temp = millis() - DISPLAY_DATA[displayindex].LAST_UPDATE; if (temp < DISPLAY_DATA[displayindex].SCROLL_DELAY) { proceed = false; } else { proceed = true; DISPLAY_DATA[displayindex].LAST_UPDATE = millis(); } //check that it has been long enough since last update if( !proceed ) { return; } //check if our start index just hit the end of the string if(text[scrollindex] != 0) { boolean blank = false; //now fill up our buffer. If we are scrolling //past the end of the string, add blank //characters for (int displaypos = 0; displaypos<8; displaypos++) { //seems like a bad habit to over-index the array, doesn't it? //but !blank prevents that from actually happening if ( !blank && text[scrollindex + displaypos] == 0 ) { blank = true; //setting blank makes above tast pass through (not over-indexing array) } if ( blank ) { buffer[displaypos] = ' '; //add empty space in place of null } else { buffer[displaypos] = text[scrollindex+displaypos]; //add char to buffer } } buffer[8]=0; writeDisplay(buffer, displaynum); //where '1' is the display number DISPLAY_DATA[displayindex].SCROLL_POSITION++; } else { //at end of string now write a fully blank line to push //that last character off the screen for(int j = 0; j<8; j++) { buffer[j] = ' '; } buffer[8]=0; writeDisplay(buffer, displaynum); //start index was at end of string, raise flag DISPLAY_DATA[displayindex].SCROLL_COMPLETE = true; } return; }