<?xml version="1.0" encoding="UTF-8"?>        <rss version="2.0"
             xmlns:atom="http://www.w3.org/2005/Atom"
             xmlns:dc="http://purl.org/dc/elements/1.1/"
             xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
             xmlns:admin="http://webns.net/mvcb/"
             xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
             xmlns:content="http://purl.org/rss/1.0/modules/content/">
        <channel>
            <title>
									Adafruit Trinket MO microcontroller - capacitive touch to toggle between LED effects - Android Devices				            </title>
            <link>https://www.tweaking4all.com/forum/android-devices/adafruit-trinket-mo-microcontroller-capacitive-touch-to-toggle-between-led-effects/</link>
            <description>Tweaking4All.com Discussion Board</description>
            <language>en-US</language>
            <lastBuildDate>Mon, 20 Apr 2026 12:12:15 +0000</lastBuildDate>
            <generator>wpForo</generator>
            <ttl>60</ttl>
							                    <item>
                        <title>Adafruit Trinket MO microcontroller - capacitive touch to toggle between LED effects</title>
                        <link>https://www.tweaking4all.com/forum/android-devices/adafruit-trinket-mo-microcontroller-capacitive-touch-to-toggle-between-led-effects/#post-3825</link>
                        <pubDate>Thu, 09 Dec 2021 12:18:09 +0000</pubDate>
                        <description><![CDATA[Code modification by Gary for LED Effects AIO;
I modified your code to use on an Adafruit Trinket MO microcontroller where I use capacitive touch to toggle between the different effects (co...]]></description>
                        <content:encoded><![CDATA[<p><em>Code modification by <a href="https://www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/#comment-563357" target="_blank" rel="noopener">Gary for LED Effects AIO</a>;</em></p>
<p>I modified your code to use on an Adafruit Trinket MO microcontroller where I use capacitive touch to toggle between the different effects (code below).</p>
<p>One key point to note is the value used for the internal resister setting. (RESISTOR_20K). Set too low and ambient light can toggle the switch. Set too high and it struggles to detect your touch. </p>
<p>Hope this compliments your awesome work in some way.</p>
<p>End result here:</p>
<p><a href="https://www.youtube.com/watch?v=0WxDgiRM9g8" target="_blank" rel="nofollow noopener ugc">https://www.youtube.com/watch?v=0WxDgiRM9g8</a></p>
<pre contenteditable="false">#include &lt;Adafruit_NeoPixel.h&gt;

#include &lt;Adafruit_FreeTouch.h&gt;

#include &lt;Adafruit_DotStar.h&gt;

#define PIN 3

#define PIN2 4

#define NUM_LEDS 111

#define NUM_LEDS2 28

// 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)TrinketMO1976!@3

// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)

Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);

Adafruit_NeoPixel innerring = Adafruit_NeoPixel(NUM_LEDS2, PIN2, NEO_GRB + NEO_KHZ800);

Adafruit_DotStar dotStar = Adafruit_DotStar(1, INTERNAL_DS_DATA, INTERNAL_DS_CLK, DOTSTAR_BGR);

Adafruit_FreeTouch qt_1 = Adafruit_FreeTouch(A0, OVERSAMPLE_4, RESISTOR_20K, FREQ_MODE_NONE);

int x = 0;

void setup() {

  //Serial.begin(115200);

  //while (!Serial);

  // Serial.println(“FreeTouch test”);

  // if (! qt_1.begin())  

  //Serial.println(“Failed to begin qt on pin A0”);

  dotStar.begin(); // Initialize pins for output

  dotStar.show(); // Turn dotstar off ASAP

  strip.begin();

  innerring.begin();

  strip.show(); // Initialize all pixels to ‘off’

  innerring.show(); // Initialize all pixels to ‘off’

  // Initialize A0 as a touch sensor

  //Serial.begin(115200);

  qt_1.begin();

  //while (!Serial);

  //Serial.println(“FreeTouch test”);

  // initialize digital pin LED_BUILTIN as an output.

  //pinMode(LED_BUILTIN, OUTPUT);

  //if (! qt_1.begin());  

  //Serial.println(“Failed to begin qt on pin A0”);

}

// *** REPLACE FROM HERE ***

void loop() {

  // —&gt; here we call the effect function &lt;—

  int counter, result = 0;

  // DIY

  //Serial.println(“\n*************************************”);

  counter = millis();

  result = qt_1.measure();

  //Serial.print(“QT 1: “); Serial.print(result);

  //Serial.print(” (“); Serial.print(millis() – counter); Serial.println(” ms)”);

  if (result &gt; 1000) {

    x++;

    strip.begin();

    strip.show();

    delay(1000);

  }

  //Serial.print(“x value: “); Serial.print(x);

  if (x == 0) {

    colorWipe(100, 100, 100, 70);

  } else if (x == 1) {

    //theaterChase(0,165,255,40);

    meteorRain(0, 165, 255, 10, 64, true, 30);

    //Twinkle(100, 100, 100, 10, 100, false);

  } else if (x == 2) {

    theaterChase(100, 100, 100, 10);

  } else if (x == 3) {

    strip.begin();

    strip.show();

    colorWipe(255, 255, 0, 70);

  } else if (x == 4) {

    theaterChase(255, 185, 100, 40);

  } else if (x == 5) {

    theaterChase(255, 185, 100, 10);

  } else if (x == 6) {

    strip.begin();

    strip.show();

    colorWipe(255, 0, 0, 70);

  } else if (x == 7) {

    theaterChase(255, 0, 0, 40);

  } else if (x == 8) {

    theaterChase(255, 0, 0, 10);

  } else if (x == 9) {

    strip.begin();

    strip.show();

    colorWipe(0, 0, 0, 0);

  } else if (x &gt; 9) {

    x = 0;

  }

}

void Twinkle(byte red, byte green, byte blue, int Count, int SpeedDelay, boolean OnlyOne) {

  setAll(0, 0, 0);

  for (int i = 0; i &lt; Count; i++) {

    setPixel(random(NUM_LEDS), red, green, blue);

    showStrip();

    delay(SpeedDelay);

    if (OnlyOne) {

      setAll(0, 0, 0);

    }

  }

  delay(SpeedDelay);

}

void theaterChase(byte red, byte green, byte blue, int SpeedDelay) {

  for (int j = 0; j &lt; 10; j++) { //do 10 cycles of chasing

    for (int q = 0; q &lt; 3; q++) {

      for (int i = 0; i &lt; NUM_LEDS; i = i + 4) {

        setPixel(i + q, red, green, blue); //turn every third pixel on

      }

      showStrip();

      delay(SpeedDelay);

      for (int i = 0; i &lt; NUM_LEDS; i = i + 4) {

        setPixel(i + q, 0, 0, 0); //turn every third pixel off

      }

    }

  }

}

void colorWipe(byte red, byte green, byte blue, int SpeedDelay) {

  for (uint16_t i = 0; i &lt; NUM_LEDS2; i++) {

    setPixelRing(i, red, green, blue);

    showRing();

    delay(SpeedDelay);

  }

}

void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {

  setAll(0, 0, 0);

  for (int i = 0; i &lt; NUM_LEDS + NUM_LEDS; i++) {

    // fade brightness all LEDs one step

    for (int j = 0; j &lt; NUM_LEDS; j++) {

      if ((!meteorRandomDecay) || (random(10) &gt; 5)) {

        fadeToBlack(j, meteorTrailDecay);

      }

    }

    // draw meteor

    for (int j = 0; j &lt; meteorSize; j++) {

      if ((i - j &lt; NUM_LEDS) &amp;&amp; (i - j &gt;= 0)) {

        setPixel(i - j, red, green, blue);

      }

    }

    showStrip();

    delay(SpeedDelay);

  }

}

void fadeToBlack(int ledNo, byte fadeValue) {

  #ifdef ADAFRUIT_NEOPIXEL_H

  // NeoPixel

  uint32_t oldColor;

  uint8_t r, g, b;

  int value;

  oldColor = strip.getPixelColor(ledNo);

  r = (oldColor &amp; 0x00ff0000 UL) &gt;&gt; 16;

  g = (oldColor &amp; 0x0000ff00 UL) &gt;&gt; 8;

  b = (oldColor &amp; 0x000000ff UL);

  r = (r &lt;= 10) ? 0 : (int) r - (r * fadeValue / 256);

  g = (g &lt;= 10) ? 0 : (int) g - (g * fadeValue / 256);

  b = (b &lt;= 10) ? 0 : (int) b - (b * fadeValue / 256);

  strip.setPixelColor(ledNo, r, g, b);

  #endif

  #ifndef ADAFRUIT_NEOPIXEL_H

  // FastLED

  leds.fadeToBlackBy(fadeValue);

  #endif

}

// —&gt; here we define the effect function &lt;—

// *** REPLACE TO HERE ***

void showStrip() {

  #ifdef ADAFRUIT_NEOPIXEL_H

  // NeoPixel

  strip.show();

  #endif

  #ifndef ADAFRUIT_NEOPIXEL_H

  // FastLED

  FastLED.show();

  #endif

}

void showRing() {

  #ifdef ADAFRUIT_NEOPIXEL_H

  // NeoPixel

  innerring.show();

  #endif

  #ifndef ADAFRUIT_NEOPIXEL_H

  // FastLED

  FastLED.show();

  #endif

}

void setPixel(int Pixel, byte red, byte green, byte blue) {

  #ifdef ADAFRUIT_NEOPIXEL_H

  // NeoPixel

  strip.setPixelColor(Pixel, strip.Color(red, green, blue));

  #endif

  #ifndef ADAFRUIT_NEOPIXEL_H

  // FastLED

  leds.r = red;

  leds.g = green;

  leds.b = blue;

  #endif

}

void setPixelRing(int Pixel, byte red, byte green, byte blue) {

  #ifdef ADAFRUIT_NEOPIXEL_H

  // NeoPixel

  innerring.setPixelColor(Pixel, innerring.Color(red, green, blue));

  #endif

  #ifndef ADAFRUIT_NEOPIXEL_H

  // FastLED

  leds.r = red;

  leds.g = green;

  leds.b = blue;

  #endif

}

void setAll(byte red, byte green, byte blue) {

  for (int i = 0; i &lt; NUM_LEDS; i++) {

    setPixel(i, red, green, blue);

  }

  showStrip();

}

void setAllRing(byte red, byte green, byte blue) {

  for (int i = 0; i &lt; NUM_LEDS; i++) {

    setPixelRing(i, red, green, blue);

  }

  showRing();

}</pre>
<p> </p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/android-devices/">Android Devices</category>                        <dc:creator>Hans</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/android-devices/adafruit-trinket-mo-microcontroller-capacitive-touch-to-toggle-between-led-effects/#post-3825</guid>
                    </item>
							        </channel>
        </rss>
		