EcoModder.com

EcoModder.com (https://ecomodder.com/forum/)
-   OpenGauge / MPGuino FE computer (https://ecomodder.com/forum/opengauge-mpguino-fe-computer.html)
-   -   Just goofing off with formatted serial output (ANSI) (https://ecomodder.com/forum/showthread.php/just-goofing-off-formatted-serial-output-ansi-2080.html)

dcb 04-30-2008 07:48 AM

Just goofing off with formatted serial output (ANSI)
 
Remember Ansi? :)

http://opengauge.org/diympggauge/serialDisplay.GIF

Code:

int lbuttonPin = 17; // Left Button, on analog 3, 
int mbuttonPin = 18; // Middle Button, on analog 4
int rbuttonPin = 19; // Right Button, on analog 5

int lbuttonBit = 8; //  pin17 is a bitmask 8 on port C 
int mbuttonBit = 16; // pin18 is a bitmask 16 on port C 
int rbuttonBit = 32; // pin19 is a bitmask 32 on port C 

//pretend we start with upressed buttons
int buttonpins = lbuttonBit + mbuttonBit + rbuttonBit;

//attach the interrupt
ISR( PCINT1_vect ){
  buttonpins &= PINC;//bypassing digitalRead for interrupt performance
}
 
void setup() {
  Serial.begin(9600);

  pinMode( lbuttonPin, INPUT );
  pinMode( mbuttonPin, INPUT );
  pinMode( rbuttonPin, INPUT );

//"turn on" the internal pullup resistors
  digitalWrite( lbuttonPin, HIGH);
  digitalWrite( mbuttonPin, HIGH);
  digitalWrite( rbuttonPin, HIGH);

//low level interrupt enable stuff
  PCICR |= (1 << PCIE1);
  PCMSK1 |= (1 << PCINT11);
  PCMSK1 |= (1 << PCINT12);
  PCMSK1 |= (1 << PCINT13); 
  Serial.print(27,BYTE);  Serial.print("[37;44m"); //white on blue
  clearScreen();
}

void clearScreen(){
  Serial.print(27,BYTE);  Serial.print("[2J"); //ansi clear screen
 
//  draw a box in ascii
  Serial.print(0xc9,BYTE); for(int x=0;x<16;x++)  Serial.print(0xcd,BYTE);Serial.println(0xbb,BYTE);
  Serial.print(0xba,BYTE); Serial.print("                ");Serial.println(0xba,BYTE);
  Serial.print(0xba,BYTE); Serial.print("                ");Serial.println(0xba,BYTE);
  Serial.print(0xc8,BYTE); for(int x=0;x<16;x++)  Serial.print(0xcd,BYTE);Serial.println(0xbc,BYTE);
  gotoXY(0,0);
}

//x=0..15, y=0..1
void gotoXY(int x, int y) {   
  Serial.print(27,BYTE);  Serial.print("[");Serial.print(y+2);
  Serial.print(";");Serial.print(x+2);Serial.print("H");
}
 
void print(char * text) {   
  Serial.print(text);
}
 
 
void loop() {   

  //print out what buttons have been pressed
  if(!(buttonpins&lbuttonBit)) {
    clearScreen();
    print("OpenGauge");
    gotoXY(9,1);
    print("MPGuino");
  }

  if(!(buttonpins&mbuttonBit)) {
    clearScreen();
    print("There's the ");
    gotoXY(0,1);
    print("middle button");
  }

  if(!(buttonpins&rbuttonBit)) {
    clearScreen();
    print("You found the");
    gotoXY(0,1);
    print("right button!!!!");
  }
 
 
  //reset the buttons
  buttonpins = lbuttonBit + mbuttonBit + rbuttonBit;

  delay(1000);
}



All times are GMT -4. The time now is 12:05 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Content Relevant URLs by vBSEO 3.5.2
All content copyright EcoModder.com