Hi everyone I am fairly new to this arduino coding, I can do a lot of the basics and have been experimenting with regular LED's, however I have ordered the Adafruit Neopixel 12. I need these circuit to work for this project I have at Uni idea for a project but I am struggling on how to code the main effects I am looking for.
So essentially, I want to send a pulse to the LED ring that will beat like a heart, and I have a mini disc motor that will work in sync with this LED. Unfortunately I haven't managed to find anything for this and I need to get this done as soon as possible.
For reference, I am using an arduino uno and the the codes I am using for the LED and Motor have been posted below. If anyone can help than that would be absolutely amazing.
This one is for the LED
#include <Adafruit_NeoPixel.h>
//Hacked from the original Adafruit library demo
#define PIN 6 //my control pin
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(16, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin();
strip.setBrightness(5); //adjust brightness here
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
//Start out with a pink brain looking color
colorWipe(strip.Color(255, 48, 48), 1); // Hot Pink
//Throb read and then fade out
heartThrob(40);
}
// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
void rainbow(uint8_t wait) {
//secret rainbow mode
uint16_t i, j;
for(j=0; j<256; j++) {
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i+j) & 255));
}
strip.show();
delay(wait);
}
}
void heartThrob(uint8_t wait) {
uint16_t i, j;
//Adjust 60 and 90 to the starting and ending colors you want to fade between.
for(j=60; j<90; j++) {
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i+j) & 255));
}
strip.show();
delay(wait);
}
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
if(WheelPos < 85) {
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}
And this one is for the motor
Motor is attached to pin 9 in series with a 5.6K resistor
*/
int i = 0;
void setup() { // bring the Motor up nicely from being off
for(i = 0 ; i <= 15; i+=1)
{
analogWrite(9, i);
delay(5);
}
}
void loop()
{
for(i = 15 ; i <= 255; i+=1)
{
analogWrite(9, i);
if (i > 150) {
delay(4);
}
if ((i > 125) && (i < 151)) {
delay(5);
}
if (( i > 100) && (i < 126)) {
delay(7);
}
if (( i > 75) && (i < 101)) {
delay(10);
}
if (( i > 50) && (i < 76)) {
delay(14);
}
if (( i > 25) && (i < 51)) {
delay(18);
}
if (( i > 1) && (i < 26)) {
delay(19);
}
}
for(i = 255; i >=15; i-=1)
{
analogWrite(9, i);
if (i > 150) {
delay(4);
}
if ((i > 125) && (i < 151)) {
delay(5);
}
if (( i > 100) && (i < 126)) {
delay(7);
}
if (( i > 75) && (i < 101)) {
delay(10);
}
if (( i > 50) && (i < 76)) {
delay(14);
}
if (( i > 25) && (i < 51)) {
delay(18);
}
if (( i > 1) && (i < 26)) {
delay(19);
}
}
delay(870);
}
Thank you guys in advance. I appreciate your help