Orientation detector

Made by behnamh8

This project is a orientation detection with feedback to a RGB LED. Orientation of the device is detected by two vertically oriented tilt sensors and depending on which side is up, LED shines a different color.

Created: January 28th, 2015

0
0
0
int tilt1Pin = D3;
int tilt2Pin = D4;

int redPin = A0;    // RED pin of the LED to PWM pin **A0**
int greenPin = D0;  // GREEN pin of the LED to PWM pin **D0**
int bluePin = D1;   // BLUE pin of the LED to PWM pin **D1**
int redValue = 255; // Full brightness for an Cathode RGB LED is 0, and off 255
int greenValue = 255; // Full brightness for an Cathode RGB LED is 0, and off 255
int blueValue = 255; // Full brightness for an Cathode RGB LED is 0, and off 255


void setup()
{
  pinMode( redPin, OUTPUT);
  pinMode( greenPin, OUTPUT);
  pinMode( bluePin, OUTPUT);
  pinMode( tilt2Pin, INPUT);
  pinMode( tilt1Pin, INPUT);


  digitalWrite( redPin, HIGH);
  digitalWrite( greenPin, HIGH);
  digitalWrite( bluePin, HIGH);


}



void loop()
{
  int val1 = digitalRead(tilt1Pin); // read from the sensor
  int val2 = digitalRead(tilt2Pin);

  digitalWrite( bluePin, HIGH);
  digitalWrite( redPin, HIGH);
  digitalWrite( greenPin, HIGH);

  if (val1 == HIGH && val2 == HIGH)   { digitalWrite( bluePin, LOW);
  color == 'B';

  }else if (val1 == LOW && val2 == HIGH)   {digitalWrite( greenPin, LOW);
  color == 'G';

  }else if (val1 == HIGH && val2 == LOW)   {digitalWrite( redPin, LOW);
  color == 'R';

  }else {digitalWrite( redPin, HIGH);
  color == 'O'; }


}
Click to Expand
x
Share this Project


About

This project is a orientation detection with feedback to a RGB LED. Orientation of the device is detected by two vertically oriented tilt sensors and depending on which side is up, LED shines a different color.