HELP! combining 2 codes!

I was trying to combine two codes but only one part is working. I tried to control the LEDS but not working :frowning: please help T^T

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
#define PIN      6
#define NUMPIXELS 2
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>
char BTdata = 0;
#include "Adafruit_MPR121.h"
#ifndef _BV
#define _BV(bit) (1 << (bit))
#endif
Adafruit_MPR121 cap = Adafruit_MPR121();
uint16_t lasttouched = 0;
uint16_t currtouched = 0;
Adafruit_SH1107 display = Adafruit_SH1107(64, 128, &Wire);

#if defined(ESP8266)
#define BUTTON_A  0
#define BUTTON_B 16
#define BUTTON_C  2
#elif defined(ESP32)
#define BUTTON_A 15
#define BUTTON_B 32
#define BUTTON_C 14
#elif defined(ARDUINO_STM32_FEATHER)
#define BUTTON_A PA15
#define BUTTON_B PC7
#define BUTTON_C PC5
#elif defined(TEENSYDUINO)
#define BUTTON_A  4
#define BUTTON_B  3
#define BUTTON_C  8
#elif defined(ARDUINO_NRF52832_FEATHER)
#define BUTTON_A 31
#define BUTTON_B 30
#define BUTTON_C 27
#else // 32u4, M0, M4, nrf52840 and 328p
#define BUTTON_A  9
#define BUTTON_B  6
#define BUTTON_C  5
#endif

void setup() {

  pixels.begin();
  Serial.begin(9600);

  Serial.println("128x64 OLED FeatherWing test");
  display.begin(0x3C, true); // Address 0x3C default
  Serial.println("OLED begun");
  display.display();
  delay(1000);
  display.clearDisplay();
  display.display();
  display.setRotation(1);
  Serial.println("Button test");
  pinMode(BUTTON_A, INPUT_PULLUP);
  pinMode(BUTTON_B, INPUT_PULLUP);
  pinMode(BUTTON_C, INPUT_PULLUP);
  // text display tests
  display.setTextSize(1);
  display.setTextColor(SH110X_WHITE);
  display.setCursor(0, 0);
  display.print("Connecting to SSID\n'adafruit':");
  display.print("connected!");
  display.println("IP: 10.0.1.23");
  display.println("Sending val #0");
  display.display(); // actually display all of the above
  if (!cap.begin(0x5A)) {
    Serial.println("MPR121 not found, check wiring?");
    while (1);
  }
  Serial.println("MPR121 found!");

}



void loop() {
 pixels.clear();
  pixels.setBrightness(10);
  pixels.setPixelColor(0, pixels.Color(0, 0, 255));
  pixels.setPixelColor(1, pixels.Color(0, 0, 255));
  pixels.show();
   

  currtouched = cap.touched();
  for (uint8_t i = 0; i < 12; i++) {
    // it if *is* touched and *wasnt* touched before, alert!
    if ((currtouched & _BV(i)) && !(lasttouched & _BV(i)) ) {
      display.clearDisplay();
      display.print(i); display.println(" GOT");
      Serial.print(i); Serial.println(" GOT");
      display.setCursor(0, 0);
      display.display();
    }
    // if it *was* touched and now *isnt*, alert!
    if (!(currtouched & _BV(i)) && (lasttouched & _BV(i)) ) {
      display.clearDisplay();
      display.print(i); display.println(" YOU");
      Serial.print(i); Serial.println(" YOU");
      display.setCursor(0, 0);
      display.display();
    }
  }
  // reset our state
  lasttouched = currtouched;
  // display.clearDisplay();
  delay(10);
  // comment out this line for detailed data from the sensor!
  return;

}


Google is your friend

combine sketch arduino

should give you some hits, poke around and see if something matches your mood.

Also: when you post code, use the </> button in the message composition window so your code looks like

for (uint8_t i=0; i<12; i++) {
// it if is touched and wasnt touched before, alert!
if ((currtouched & _BV(i)) && !(lasttouched & _BV(i)) ) {
display.clearDisplay();
display.print(i); display.println(" GOT");
Serial.print(i); Serial.println(" GOT");
display.setCursor(0,0);
display.display();
}

or use "Copy for Forum" from the Edit menu in the IDE, then paste here. Once for each of the two sketches.

Please use the "Auto Format" command from the Tools menu in the IDE first, so your code looks like this:

  for (uint8_t i = 0; i < 12; i++) {
    // it if is touched and wasnt touched before, alert!
    if ((currtouched & _BV(i)) && !(lasttouched & _BV(i)) ) {
      display.clearDisplay();
      display.print(i); display.println(" GOT");
      Serial.print(i); Serial.println(" GOT");
      display.setCursor(0, 0);
      display.display();
    }
  }

HTH

a7

Thanks!

This is also a terrible description of your problem. How is it not working? What is it doing? What did you intend it to do? What is on your display? What is showing up in the Serial Monitor?