Heyyo!
It has been way to long since I coded with Arduino, and the language seems almost foreign to me now honestly, and I want do one last project. My goal is to use the accelerometer to toggle 12V LED strips to on or off. Luckily, I saved the code of a past project (years ago) to toggle some servos and was going to use the same trigger and detection settings. Only issue now is I don't know where to start on the code.
So long and short, here is my end game. My girlfriend will flick her wrists, and 12V will be applied to the LEDs lighting them up. Simple goal, but I know the 3.2 can't handle 5V. Is what I am doing possible? What should I modify in my code to get there right outputs?
It has been way to long since I coded with Arduino, and the language seems almost foreign to me now honestly, and I want do one last project. My goal is to use the accelerometer to toggle 12V LED strips to on or off. Luckily, I saved the code of a past project (years ago) to toggle some servos and was going to use the same trigger and detection settings. Only issue now is I don't know where to start on the code.
Code:
// Basic Inertial Monitoring Unit (IMU) using Madgwick filter.
//
// To view this data, use the Arduino Serial Monitor to watch the
// scrolling angles, or run the OrientationVisualiser example in Processing.
#include <NXPMotionSense.h>
#include <Wire.h>
#include <EEPROM.h>
#include <PWMServo.h>
NXPMotionSense imu;
NXPSensorFusion filter;
PWMServo servo1, servo2;
float accumRoll, accumPitch, accumHeading;
float toggle;
boolean tripped, ledToggle;
void setup() {
Serial.begin(9600);
servo1.attach(9);
servo2.attach(4);
imu.begin();
filter.begin(100);
pinMode(13, OUTPUT);
}
void loop() {
float ax, ay, az;
float gx, gy, gz;
float mx, my, mz;
float roll, pitch, heading;
if (imu.available()) {
// Read the motion sensors
imu.readMotionSensor(ax, ay, az, gx, gy, gz, mx, my, mz);
filter.update(gx, gy, gz, ax, ay, az, mx, my, mz);
accumRoll *= 0.9;
accumPitch *= 0.9;
accumHeading *= 0.9;
accumRoll += abs(gx)*.1;
accumPitch += abs(gy)*.1;
accumHeading += abs(gz)*.1;
// print the heading, pitch and roll
float totMovement = sqrt(accumRoll*accumRoll+accumPitch*accumPitch+accumHeading*accumHeading);
float togF = 0;
if(totMovement>280){
togF = totMovement;
}
toggle = toggle*.95 + (0.05*togF);
if(toggle>250){
if(!tripped){
tripped = true;
ledToggle = !ledToggle;
}
}else{
if(tripped){
tripped = false;
}
}
digitalWrite(13, ledToggle);
roll = filter.getRoll();
Serial.println(toggle);
//servo2.write(180-int(abs(roll)));
if(ledToggle){
servo1.write(155);
servo2.write(50);
}else{
servo1.write(80);
servo2.write(115);
}
}
}
So long and short, here is my end game. My girlfriend will flick her wrists, and 12V will be applied to the LEDs lighting them up. Simple goal, but I know the 3.2 can't handle 5V. Is what I am doing possible? What should I modify in my code to get there right outputs?