Go Back   EcoModder Forum > EcoModding > Instrumentation > OpenGauge / MPGuino FE computer
Register
Now


Reply
 
Submit Tools LinkBack Thread Tools
Old 04-30-2008, 08:48 AM   #1 (permalink)
dcb
Master EcoModder
 
dcb's Avatar
 
Join Date: Feb 2008
Location: 3rd rock
Posts: 1,310

pimp mobile - '81 gs 250 t
90 day: 96.29 mpg (US)
Just goofing off with formatted serial output (ANSI)

Remember Ansi?



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);
}


(Support Ecomodder.com & get rid of these annoying ads!)      
 
  Reply With Quote
Reply

Thread Tools





Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0 RC5
All content copyright EcoModder.com