Thread: Super MPGuino?
View Single Post
Old 02-23-2010, 02:23 PM   #67 (permalink)
bobski
EcoModding Apprentice
 
Join Date: Jan 2010
Location: Newark, DE
Posts: 143

'91 CRX - '91 Honda CRX DX
90 day: 34.91 mpg (US)
Thanks: 0
Thanked 14 Times in 14 Posts
Okay... The big difference I notice between the standard boards and the mega is the pin numbering when using the analog pins as standard digital I/O. The scheme is the same but the numbering is different: the analog pins can be addressed as digital pins just beyond the range of dedicated digital pins. In the case of standard boards, the digital pins are numbered 0-13, so the digital-analog pins become 14-19 (or 14-21 for the Seeeduino). The mega boards have 54 digital I/O pins (0-53) so the analog pins become 54-69. The Seeduino Mega has an additional bank of 16 digital I/O pins, but these are unnumbered, so the standard mega numbering scheme applies.

Paste this into Arduino and upload it to your board. Grounding any of the first 13 standard digital pins (0-12), or any of the 16 analog pins should make the "L" indicator LED light. Pin 13 gets left out because it's being used to drive the LED.
Code:
int pinValue;

void setup()
{
  pinMode(0, INPUT);           //Set up standard digital IO pins as inputs, using internal pullups
  digitalWrite(0,HIGH);
  pinMode(1, INPUT);
  digitalWrite(1,HIGH);
  pinMode(2, INPUT);
  digitalWrite(2,HIGH);
  pinMode(3, INPUT);
  digitalWrite(3,HIGH);
  pinMode(4, INPUT);
  digitalWrite(4,HIGH);
  pinMode(5, INPUT);
  digitalWrite(5,HIGH);
  pinMode(6, INPUT);
  digitalWrite(6,HIGH);
  pinMode(7, INPUT);
  digitalWrite(7,HIGH);
  pinMode(8, INPUT);
  digitalWrite(8,HIGH);
  pinMode(9, INPUT);
  digitalWrite(9,HIGH);
  pinMode(10, INPUT);
  digitalWrite(10,HIGH);
  pinMode(11, INPUT);
  digitalWrite(11,HIGH);
  pinMode(12, INPUT);
  digitalWrite(12,HIGH);
  
  pinMode(13, OUTPUT);         //Use the LED on pin 13 as as an indicator
  
  pinMode(54, INPUT);          //Set up mega's analog pins as digital inputs, using internal pullups
  digitalWrite(54,HIGH);
  pinMode(55, INPUT);
  digitalWrite(55,HIGH);
  pinMode(56, INPUT);
  digitalWrite(56,HIGH);
  pinMode(57, INPUT);
  digitalWrite(57,HIGH);
  pinMode(58, INPUT);
  digitalWrite(58,HIGH);
  pinMode(59, INPUT);
  digitalWrite(59,HIGH);
  pinMode(60, INPUT);
  digitalWrite(60,HIGH);
  pinMode(61, INPUT);
  digitalWrite(61,HIGH);
  pinMode(62, INPUT);
  digitalWrite(62,HIGH);
  pinMode(63, INPUT);
  digitalWrite(63,HIGH);
  pinMode(64, INPUT);
  digitalWrite(64,HIGH);
  pinMode(65, INPUT);
  digitalWrite(65,HIGH);
  pinMode(66, INPUT);
  digitalWrite(66,HIGH);
  pinMode(67, INPUT);
  digitalWrite(67,HIGH);
  pinMode(68, INPUT);
  digitalWrite(68,HIGH);
  pinMode(69, INPUT);
  digitalWrite(69,HIGH);
}

void loop()
{
  pinValue = 0;                            //reset pinValue
  
  pinValue = pinValue + digitalRead(0);    //read pin values and add them up
  pinValue = pinValue + digitalRead(1);
  pinValue = pinValue + digitalRead(2);
  pinValue = pinValue + digitalRead(3);
  pinValue = pinValue + digitalRead(4);
  pinValue = pinValue + digitalRead(5);
  pinValue = pinValue + digitalRead(6);
  pinValue = pinValue + digitalRead(7);
  pinValue = pinValue + digitalRead(8);
  pinValue = pinValue + digitalRead(9);
  pinValue = pinValue + digitalRead(10);
  pinValue = pinValue + digitalRead(11);
  pinValue = pinValue + digitalRead(12);
  
  pinValue = pinValue + digitalRead(54);
  pinValue = pinValue + digitalRead(55);
  pinValue = pinValue + digitalRead(56);
  pinValue = pinValue + digitalRead(57);
  pinValue = pinValue + digitalRead(58);
  pinValue = pinValue + digitalRead(59);
  pinValue = pinValue + digitalRead(60);
  pinValue = pinValue + digitalRead(61);
  pinValue = pinValue + digitalRead(62);
  pinValue = pinValue + digitalRead(63);
  pinValue = pinValue + digitalRead(64);
  pinValue = pinValue + digitalRead(65);
  pinValue = pinValue + digitalRead(66);
  pinValue = pinValue + digitalRead(67);
  pinValue = pinValue + digitalRead(68);
  pinValue = pinValue + digitalRead(69);
  
  if(pinValue < 29)
  {digitalWrite(13,HIGH);}
  else
  {digitalWrite(13,LOW);}
}
  Reply With Quote
The Following User Says Thank You to bobski For This Useful Post:
gtkid2002 (02-23-2010)