Skip to content

Instantly share code, notes, and snippets.

@timothylhuillier
Created February 11, 2015 07:45
Show Gist options
  • Save timothylhuillier/22240e72cdae731a6f74 to your computer and use it in GitHub Desktop.
Save timothylhuillier/22240e72cdae731a6f74 to your computer and use it in GitHub Desktop.
#include <Akeru.h>
#include <LPD8806.h>
#include "SPI.h" // Comment out this line if using Trinket or Gemma
#include <SoftwareSerial.h>
/*
Double Analog input, Double analog output, serial output
Reads from two analog input pins, a T000020 Accelerometer Module connected
to I0 and I1, maps the result to a range from 0 to 255
and uses the result to set the pulsewidth modulation (PWM) on two T010111
LED Modules connected on O0 and O1.
Also prints the results to the serial monitor.
created 29 Dec. 2008
Modified 4 Sep 2010
by Tom Igoe
modified 7 dec 2010
by Davide Gomba
This example code is in the public domain.
PDF à suivre si besoin :http://www.mouser.fr/catalog/specsheets/TinkerKit2-3AxisAccelerometer.pdf
*/
// LEDS
int nLEDs = 6; // Number of RGB LEDs in strand
// Chose 2 pins for output; can be any valid output pins:
int dataPin = 2;
int clockPin = 3;
// First parameter is the number of LEDs in the strand. The LED strips
// are 32 LEDs per meter but you can extend or cut the strip. Next two
// parameters are SPI data and clock pins:
LPD8806 strip = LPD8806(nLEDs, dataPin, clockPin);
// ACCELEROMETRE
#define O0 11 // LED 1
#define O1 10 // led 2
#define I0 A0 // X
#define I1 A1 // Y
// These constants won't change. They're used to give names
// to the pins used:
const int analogInPin1 = I0; // Analog input pin that the Accelerometer's first pin is attached to
const int analogInPin2 = I1; // Analog input pin that the Accelerometer's second pin is attached to
const int analogOutPin1= O0; // Analog output pin that the LED is attached to
const int analogOutPin2= O1; // Analog output pin that the LED is attached to
int sensorValue1 = 0; // value read from the Accelerometer's first pin
int sensorValue2 = 0; // value read from the Accelerometer's second pin
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
// Init modem Sigfox
Akeru.begin();
// Start up the LED strip
strip.begin();
// Update the strip, to start they are all 'off'
strip.show();
}
void loop() {
// read the both analog in values:
sensorValue1 = analogRead(analogInPin1); // X
sensorValue2 = analogRead(analogInPin2); // Y
// print the results to the serial monitor:
Serial.print("accelerometer X = ");
Serial.print(sensorValue1);
Serial.print("\t accelerometer Y = ");
Serial.print(sensorValue2);
Serial.print("\n");
if(sensorValue1 < 450 || sensorValue1 > 800) {
chute();
}
else if (sensorValue2 < 390 || sensorValue2 > 750){
chute();
}
// wait 10 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(300);
}
// enclenche la chutte
void chute(){
Serial.print("CHUTTTTTTTTTTTTE \n");
theaterChaseRainbow(3);
// Wait for availability of the modem
while (!Akeru.isReady()) {
Serial.println("Modem not ready");
delay(1000);
}
// Send in the mighty internet!
Akeru.send(&"code", sizeof(500)); // sa retourne {"code" : 28515 }
theaterChaseRainbow(7);
}
/* GESTION DES LEDs*/
//Theatre-style crawling lights with rainbow effect
void theaterChaseRainbow(uint8_t thisDelay) {
for (int j=0; j < 384; j++) { // cycle all 384 colors in the wheel
for (int q=0; q < 3; q++) {
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, Wheel( (i+j) % 384)); //turn every third pixel on
}
strip.show();
delay(thisDelay);
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, 0); //turn every third pixel off
}
}
}
}
//Input a value 0 to 384 to get a color value.
//The colours are a transition r - g -b - back to r
uint32_t Wheel(uint16_t WheelPos)
{
byte r, g, b;
switch(WheelPos / 128)
{
case 0:
r = 127 - WheelPos % 128; //Red down
g = WheelPos % 128; // Green up
b = 0; //blue off
break;
case 1:
g = 127 - WheelPos % 128; //green down
b = WheelPos % 128; //blue up
r = 0; //red off
break;
case 2:
b = 127 - WheelPos % 128; //blue down
r = WheelPos % 128; //red up
g = 0; //green off
break;
}
return(strip.Color(r,g,b));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment