Energia: Difference between revisions

From air
Jump to navigation Jump to search
Line 5: Line 5:


==Examples==
==Examples==
===Potentiometer==
[[File:Msp430analogread.jpg|200px|thumb|right|Analog Read (A0 or P1_0)]]
[[File:Msp430analogread.jpg|200px|thumb|right|Analog Read (A0 or P1_0)]]
<pre>
<pre>
Line 29: Line 30:
// after the last reading:
// after the last reading:
delay(10);
delay(10);
}

</pre>



===3 Buttons Pad===
[[File:Plotjoueurs.jpg|200px|thumb|right|3 Buttons Pad]]

<pre>
/*
Tree buttons pad
*/

// set pin numbers:
const int button1Pin = P1_3; // the number of the pushbutton pin
const int button2Pin = P1_4; // the number of the pushbutton pin
const int button3Pin = P1_5; // the number of the pushbutton pin
const int ledPin = GREEN_LED; // the number of the LED pin

// variables will change:
boolean ledState = false; // variable for reading the pushbutton status
int buttonsStates = 0; // variable for reading the pushbutton status

void setup() {
Serial.begin(9600); // starts the serial monitor
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(button1Pin, INPUT_PULLUP);
pinMode(button2Pin, INPUT_PULLUP);
pinMode(button3Pin, INPUT_PULLUP);
buttonsStates=readButtonsStates();
Serial.println(buttonsStates);
}

int readButtonsStates(){
int _buttonsStates=0;
if (digitalRead(button1Pin) == LOW) {
_buttonsStates |= B1;
}
if (digitalRead(button2Pin) == LOW) {
_buttonsStates |= B10;
}
if (digitalRead(button3Pin) == LOW) {
_buttonsStates |= B100;
}
return _buttonsStates;
}

void toogle(){
if (ledState) {
// turn LED off:
digitalWrite(ledPin, LOW);
} else {
// turn LED on:
digitalWrite(ledPin, HIGH);
}
ledState=!ledState;
}

void loop(){

int _buttonsStates=readButtonsStates();
// send changes only
if(buttonsStates != _buttonsStates) {
buttonsStates = _buttonsStates;
Serial.println(buttonsStates);
toogle();
}
delay(50);
}
}



Revision as of 11:12, 26 February 2013

Energia IDE

Energia is a fork of Arduino’s Processing IDE for TI’s MSP430 microcontrollers.


Examples

=Potentiometer

Analog Read (A0 or P1_0)
const int analogInPin = A0;  // or P1_0 with Launchpad P1.0 Analog input pin that the potentiometer is attached to

int sensorValue = 0;        // value read from the pot

void setup() {
  // initialize serial communications at 9600 bps:
  Serial.begin(9600); // 4800 with msp430g2231
}

void loop() {
  // read the analog in value:
  sensorValue = analogRead(analogInPin);            

  // print the results to the serial monitor:
  Serial.print("sensor = " );                       
  Serial.print(sensorValue);      
  Serial.println();   

  // wait 10 milliseconds before the next loop
  // for the analog-to-digital converter to settle
  // after the last reading:
  delay(10);                     
}


3 Buttons Pad

3 Buttons Pad
/*
Tree buttons pad
 */

// set pin numbers:
const int button1Pin = P1_3;     // the number of the pushbutton pin
const int button2Pin = P1_4;     // the number of the pushbutton pin
const int button3Pin = P1_5;     // the number of the pushbutton pin
const int ledPin =  GREEN_LED;      // the number of the LED pin

// variables will change:
boolean ledState = false;      // variable for reading the pushbutton status
int buttonsStates = 0;         // variable for reading the pushbutton status

void setup() {
  Serial.begin(9600);          // starts the serial monitor
  
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(button1Pin, INPUT_PULLUP);     
  pinMode(button2Pin, INPUT_PULLUP);     
  pinMode(button3Pin, INPUT_PULLUP);
  
  buttonsStates=readButtonsStates();
  Serial.println(buttonsStates);
}

int readButtonsStates(){
  int _buttonsStates=0;
  
  if (digitalRead(button1Pin) == LOW) { 
    _buttonsStates |= B1; 
  }
  if (digitalRead(button2Pin) == LOW) { 
    _buttonsStates |= B10; 
  }
  if (digitalRead(button3Pin) == LOW) { 
    _buttonsStates |= B100; 
  }
  return _buttonsStates;
} 

void toogle(){
  if (ledState) {     
    // turn LED off:    
    digitalWrite(ledPin, LOW);  
  } else {
    // turn LED on:
    digitalWrite(ledPin, HIGH); 
  }
  ledState=!ledState;
}

void loop(){

  int _buttonsStates=readButtonsStates();
  
  // send changes only
  if(buttonsStates != _buttonsStates)  {
    buttonsStates = _buttonsStates;
    Serial.println(buttonsStates);
    toogle();
  }
  
  delay(50);
}

Supported Boards


Pin mapping

https://github.com/energia/Energia/wiki/Hardware#wiki-LaunchPad_MSP430G2452

Links