Energia
Jump to navigation
Jump to search
Energia is a fork of Arduino’s Processing IDE for TI’s MSP430 microcontrollers.
Examples
Potentiometer
const int analogInPin = A0; // or P1_0 with Launchpad P1.0 Analog input pin that the potentiometer is attached to // or PB5 with StellarPad PB5 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
/* 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.print(buttonsStates); toogle(); // for debug } delay(50); }
Récupération de la sortie avec Node.js
// launchpad.js <port> var port = process.argv[2]; var serialport = require('serialport'); var sp = new serialport.SerialPort(port, { baudrate: 9600, parser: serialport.parsers.readline('\r\n')}); sp.on('data', function(line) { console.log(line); });
npm install serialport node launchpad.js /dev/tty.uart-XYZ
Supported Boards
- LaunchPad with msp430g2231,
- LaunchPad with msp430g2452,
- LaunchPad with msp430g2553,
- FraunchPad with msp430fr5739
- Stellaris Launchpad.
Pin mapping
https://github.com/energia/Energia/wiki/Hardware#wiki-LaunchPad_MSP430G2452