Merging codes with Arduino

The first code
#include <Adafruit_NeoPixel.h>
#ifdef AVR
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif

// Digital IO pin connected to the button. This will be driven with a
// pull-up resistor so the switch pulls the pin to ground momentarily.
// On a high -> low transition the button press logic will execute.
int sensorPin=0;
boolean val =0;

#define PIXEL_PIN 9 // Digital IO pin connected to the NeoPixels.

#define PIXEL_COUNT 8 // Number of NeoPixels

// Declare our NeoPixel strip object:
Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);

boolean oldState = HIGH;
int mode = 0; // Currently-active animation mode, 0-9

void setup() {

strip.begin(); // Initialize NeoPixel strip object (REQUIRED)
strip.show(); // Initialize all pixels to 'off'
pinMode(sensorPin, INPUT);
}

void loop() {
val =digitalRead(sensorPin);

if(val==HIGH) {

delay(20);

val = digitalRead(sensorPin);
if(val == LOW) {
if(++mode > 6) mode = 0;
switch(mode) {
case 0:
colorWipe(strip.Color( 0, 0, 0), 50);
break;
case 1:
colorWipe(strip.Color(255, 0, 0), 50);
break;
case 2:
colorWipe(strip.Color( 0, 255, 0), 50);
break;
case 3:
colorWipe(strip.Color( 0, 0, 255), 50);
break;
case 4:
theaterChase(strip.Color(127, 127, 127), 50);
break;
case 5:
theaterChase(strip.Color(127, 0, 0), 50);
break;
case 6:
theaterChase(strip.Color( 0, 0, 127), 50);
break;

 }

}
}
}

void colorWipe(uint32_t color, int wait) {
for(int i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, color);
strip.show();
delay(wait);
}
}

void theaterChase(uint32_t color, int wait) {
for(int a=0; a<10; a++) {
for(int b=0; b<3; b++) {
strip.clear();

 for(int c=b; c<strip.numPixels(); c += 3) {
   strip.setPixelColor(c, color); 
 }
 strip.show(); 
 delay(wait); 

}
}
}

void rainbow(int wait) {

for(long firstPixelHue = 0; firstPixelHue < 3*65536; firstPixelHue += 256) {
for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...

 int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());

 strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));

}
strip.show();
delay(wait);
}
}

void theaterChaseRainbow(int wait) {
int firstPixelHue = 0;
for(int a=0; a<30; a++) {
for(int b=0; b<3; b++) {
strip.clear();

 for(int c=b; c<strip.numPixels(); c += 3) {
   
   int      hue   = firstPixelHue + c * 65536L / strip.numPixels();
   uint32_t color = strip.gamma32(strip.ColorHSV(hue)); // hue -> RGB
   strip.setPixelColor(c, color); 
 }
 strip.show();                
 delay(wait);                 
 firstPixelHue += 65536 / 90; 

}
}
}

The last one

#include <Adafruit_NeoPixel.h>
#ifdef AVR
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif

#define PIXEL_PIN 9

#define PIXEL_COUNT 8

// Declare our NeoPixel strip object:
Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);

boolean oldState = HIGH;
int mode = 0;

int Sensor = A0;

int clap = 0;
long detection_range_start = 0;
long detection_range = 0;
boolean status_lights = false;
void setup() {
pinMode(Sensor, INPUT);
pinMode(13,OUTPUT);

strip.begin();
strip.show();

}
void loop() {
int status_sensor = digitalRead(Sensor);
if (status_sensor == 0)
{
if (clap == 0)
{
detection_range_start = detection_range = millis();
clap++;
}
else if (clap > 0 && millis()-detection_range >= 50)
{
detection_range = millis();
clap++;
}
}
if (millis()-detection_range_start >= 400)
{
if (clap == 2)
{
if (!status_lights)
{
status_lights = true;
digitalWrite(13, HIGH);
}
else if (status_lights)
{
status_lights = false;
digitalWrite(13, LOW);
}
}
clap = 0;
}
}

Show us your attempt and say what happened. If you have no idea how to start then Merging code will give you a good start.

The easier you make it to read and copy your code the more likely it is that you will get help

Please follow the advice given in the link below when posting code , use code tags and post the code here

If you get errors when compiling please copy them from the IDE using the "Copy error messages" button and paste the clipboard here in code tags

What is the combined code supposed to do ?

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.