MSP430 MAGIC CUBE

on Friday, June 27, 2014







Hi everyone . i did led fun project using msp430 launchpad.This project has four leds are triggered by msp430 two get different colors. the colors combination of two led color enhanced by paper cube. the color leds used in this project are red,green,blue,yellow. The color mixing is achieved by  simply glow the two led at same time for example when red and yellow leds glow together it produce orange color.
The software used for program the MSP430 is ENERGIA. you can download energia software at the bellow link:

http://energia.nu/download/

CODING:

In this project i used two kind of program

1. Contionusly change the cube color in certain delay.
2.Change color when we push the push button in msp430 launchpad.

Code for contionusly change the cube color in certain delay:

 const int ledPin = RED_LED;
const int green =P1_4 ;
const int blue = P1_7;
const int yellow = P1_6;
void setup()
{
  pinMode(ledPin, OUTPUT);
   pinMode(green, OUTPUT);
    pinMode(blue, OUTPUT);
     pinMode(yellow, OUTPUT);
 
}

void loop()
{
 digitalWrite(ledPin, HIGH);
   digitalWrite(green, LOW);
   digitalWrite(blue, LOW);
   digitalWrite(yellow, LOW);
  delay(3000);
  digitalWrite(ledPin, LOW);
   digitalWrite(green, HIGH);
   digitalWrite(blue, LOW);
   digitalWrite(yellow, LOW);
   delay(3000);
   digitalWrite(ledPin, LOW);
   digitalWrite(green, LOW);
   digitalWrite(blue, HIGH);
   digitalWrite(yellow, LOW);
   delay(3000);
   digitalWrite(ledPin, LOW);
   digitalWrite(green, LOW);
   digitalWrite(blue, LOW);
   digitalWrite(yellow, HIGH);
   delay(3000);
   digitalWrite(ledPin, HIGH);
   digitalWrite(green, LOW);
   digitalWrite(blue, LOW);
   digitalWrite(yellow, HIGH);
  delay(3000);
  digitalWrite(ledPin, LOW);
   digitalWrite(green, LOW);
   digitalWrite(blue, HIGH);
   digitalWrite(yellow, HIGH);
   delay(3000);
  digitalWrite(ledPin, HIGH);
   digitalWrite(green, HIGH);
   digitalWrite(blue, HIGH);
   digitalWrite(yellow, LOW);
  delay(3000);
  digitalWrite(ledPin, LOW);
   digitalWrite(green, HIGH);
   digitalWrite(blue, LOW);
   digitalWrite(yellow, HIGH);
   delay(3000);
}



Code for change color when we push the push button in msp430 launchpad:


 const int  buttonPin = PUSH2; 
const int ledPin = RED_LED;
const int green =P1_4 ;
const int blue = P1_7;
const int yellow = P1_6;

int buttonPushCounter = 0;   // counter for the number of button presses
int buttonState = 0;         // current state of the button
int lastButtonState = 0;     // previous state of the button

void setup() {
  // initialize the button pin as a input:
  pinMode(buttonPin, INPUT_PULLUP);
  // initialize the LED as an output:
  pinMode(ledPin, OUTPUT);
   pinMode(green, OUTPUT);
    pinMode(blue, OUTPUT);
     pinMode(yellow, OUTPUT);
  // initialize serial communication:

}


void loop() {
  // read the pushbutton input pin:
  buttonState = digitalRead(buttonPin);

  // compare the buttonState to its previous state
  if (buttonState != lastButtonState) {
    // if the state has changed, increment the counter
    if (buttonState == HIGH) {
      // if the current state is HIGH then the button
      // wend from off to on:
      buttonPushCounter++;
   
    }
 
  }
 
  lastButtonState = buttonState;

 
  if (buttonPushCounter== 2) {
     digitalWrite(ledPin, HIGH);
   digitalWrite(green, LOW);
   digitalWrite(blue, LOW);
   digitalWrite(yellow, LOW);
  }else if(buttonPushCounter == 3)
  {
    digitalWrite(ledPin, LOW);
   digitalWrite(green, HIGH);
   digitalWrite(blue, LOW);
   digitalWrite(yellow, LOW);
 
  }else if(buttonPushCounter == 4)
  {
   digitalWrite(ledPin, LOW);
   digitalWrite(green, LOW);
   digitalWrite(blue, HIGH);
   digitalWrite(yellow, LOW);
 
  }
  else if(buttonPushCounter == 5)
  {
   digitalWrite(ledPin, LOW);
   digitalWrite(green, LOW);
   digitalWrite(blue, LOW);
   digitalWrite(yellow, HIGH);
 
  }  else if(buttonPushCounter == 7)
  {
   digitalWrite(ledPin, HIGH);
   digitalWrite(green, LOW);
   digitalWrite(blue, LOW);
   digitalWrite(yellow, HIGH);
 
  } else if(buttonPushCounter == 6)
  {
   digitalWrite(ledPin, LOW);
   digitalWrite(green, LOW);
   digitalWrite(blue, HIGH);
   digitalWrite(yellow, HIGH);
 
  }else if(buttonPushCounter == 8)
  {
   digitalWrite(ledPin, HIGH);
   digitalWrite(green, HIGH);
   digitalWrite(blue, HIGH);
   digitalWrite(yellow, LOW);
 
  }
  else if(buttonPushCounter == 9)
  {
   digitalWrite(ledPin, HIGH);
   digitalWrite(green, LOW);
   digitalWrite(blue, HIGH);
   digitalWrite(yellow, LOW);
 
  }
  else if(buttonPushCounter == 10)
  {
   digitalWrite(ledPin, LOW);
   digitalWrite(green, HIGH);
   digitalWrite(blue, LOW);
   digitalWrite(yellow, HIGH);
 
  }
 else {
   digitalWrite(ledPin, LOW);
   digitalWrite(green, LOW);
   digitalWrite(blue, LOW);
   digitalWrite(yellow, LOW);
  }
 
}










0 comments:

Post a Comment