Wheel of fortune

#include <Adafruit_NeoPixel.h>

#define LEDRING_PIN 6
#define NUM_PIXELS 192  // Assuming sixteen rings of 12 pixels each

Adafruit_NeoPixel ledRings = Adafruit_NeoPixel(NUM_PIXELS, LEDRING_PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  ledRings.begin();
  ledRings.show(); // Initialize all pixels to 'off'
  randomSeed(analogRead(0)); // Seed the random number generator with an analog reading
}

void loop() {
  // Turn off all neopixel rings
  showSolidColor(0, NUM_PIXELS - 1, 0, 0, 0);
  delay(50);  // Short pause

  // Sequentially turn on each neopixel ring and turn off the previous one
  for (int i = 0; i < NUM_PIXELS; i += 12) {
    showSolidColor(i, i + 11, random(200, 255), random(200, 255), random(200, 255));
    delay(50);  // Faster pause between neopixel rings
  }

  // Stop at a random position with exponential slowdown
  int randomPos = random(NUM_PIXELS);
  showSolidColor(0, randomPos, 0, 0, 0);

  // Exponential slowdown
  for (int delayTime = 50; delayTime >= 5; delayTime *= 0.9) {
    delay(delayTime);
  }
}

void showSolidColor(int startPixel, int endPixel, int r, int g, int b) {
  for (int i = 0; i < NUM_PIXELS; i++) {
    if (i >= startPixel && i <= endPixel) {
      ledRings.setPixelColor(i, r, g, b);
    } else {
      ledRings.setPixelColor(i, 0, 0, 0); // Turn off other pixels
    }
  }
  ledRings.show();
}

i have some problems with the code aswel as the circuit.
the intention is that each neopixel ring turns on so that i have an circular motion.
but it goes very slow now and with decreasing the delay it doesn't change.
maybe its because i use the power source of the arduino.
but when i use the external power supply they don't even turn on.
maybe you know where my mistake is?
i would also like that they slow down when i get to the random stopping point but i haven't come so far.

thanks in advance for the help

The power problem is probably because you have your power supply going through the breadboard. Connect the neopixel power directly to the power supply (no breadboard). You can use the breadboard to supply power to the Arduino (low amperes). Power problems can badly effect good code... so get your power connected directly and try again.

Add a 470 ohm resistor from Arduino pin 6 to the DIN of the Neopixel.
Add a 1000uf electrolytic capacitor across your power (Vcc to GND on the Neopixel).

It looks like your first Neopixel is "9 o'clock" and "rotates" counter-clockwise.
clock

Use WOKWI.COM and these files...

"sketch.ino" tab:

#include <Adafruit_NeoPixel.h>

#define LEDRING_PIN 6
#define NUM_PIXELS 192  // Assuming sixteen rings of 12 pixels each

Adafruit_NeoPixel ledRings = Adafruit_NeoPixel(NUM_PIXELS, LEDRING_PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  ledRings.begin();
  ledRings.show(); // Initialize all pixels to 'off'
  randomSeed(analogRead(0)); // Seed the random number generator with an analog reading
}

void loop() {
  // Turn off all neopixel rings
  showSolidColor(0, NUM_PIXELS - 1, 0, 0, 0);
  delay(50);  // Short pause

  // Sequentially turn on each neopixel ring and turn off the previous one
  for (int i = 0; i < NUM_PIXELS; i += 12) {
    showSolidColor(i, i + 11, random(200, 255), random(200, 255), random(200, 255));
    delay(50);  // Faster pause between neopixel rings
  }

  // Stop at a random position with exponential slowdown
  int randomPos = random(NUM_PIXELS);
  showSolidColor(0, randomPos, 0, 0, 0);

  // Exponential slowdown
  for (int delayTime = 50; delayTime >= 5; delayTime *= 0.9) {
    delay(delayTime);
  }
}

void showSolidColor(int startPixel, int endPixel, int r, int g, int b) {
  for (int i = 0; i < NUM_PIXELS; i++) {
    if (i >= startPixel && i <= endPixel) {
      ledRings.setPixelColor(i, r, g, b);
    } else {
      ledRings.setPixelColor(i, 0, 0, 0); // Turn off other pixels
    }
  }
  ledRings.show();
}

"diagram.json" tab:

{
  "version": 1,
  "author": "Anonymous maker",
  "editor": "wokwi",
  "parts": [
    { "type": "wokwi-arduino-nano", "id": "nano", "top": -216, "left": 172.3, "attrs": {} },
    {
      "type": "wokwi-led-ring",
      "id": "ring1",
      "top": -368.89,
      "left": -5.97,
      "attrs": { "pixels": "12" }
    },
    {
      "type": "wokwi-led-ring",
      "id": "ring2",
      "top": -445.69,
      "left": 90.03,
      "attrs": { "pixels": "12" }
    },
    {
      "type": "wokwi-led-ring",
      "id": "ring3",
      "top": -474.49,
      "left": 205.23,
      "attrs": { "pixels": "12" }
    },
    {
      "type": "wokwi-led-ring",
      "id": "ring4",
      "top": -445.69,
      "left": 320.43,
      "attrs": { "pixels": "12" }
    },
    {
      "type": "wokwi-led-ring",
      "id": "ring5",
      "top": -359.29,
      "left": 406.83,
      "attrs": { "pixels": "12" }
    },
    {
      "type": "wokwi-led-ring",
      "id": "ring6",
      "top": -244.09,
      "left": -44.37,
      "attrs": { "pixels": "12" }
    },
    {
      "type": "wokwi-led-ring",
      "id": "ring7",
      "top": -234.49,
      "left": 445.23,
      "attrs": { "pixels": "12" }
    },
    {
      "type": "wokwi-led-ring",
      "id": "ring8",
      "top": -122.8,
      "left": -3.4,
      "attrs": { "pixels": "12" }
    },
    {
      "type": "wokwi-led-ring",
      "id": "ring9",
      "top": -109.69,
      "left": 406.83,
      "attrs": { "pixels": "12" }
    },
    {
      "type": "wokwi-led-ring",
      "id": "ring10",
      "top": -32.89,
      "left": 90.03,
      "attrs": { "pixels": "12" }
    },
    {
      "type": "wokwi-led-ring",
      "id": "ring11",
      "top": -32.89,
      "left": 320.43,
      "attrs": { "pixels": "12" }
    },
    {
      "type": "wokwi-led-ring",
      "id": "ring12",
      "top": 5.51,
      "left": 205.23,
      "attrs": { "pixels": "12" }
    },
    { "type": "wokwi-vcc", "id": "vcc1", "top": -373.64, "left": -38.4, "attrs": {} },
    { "type": "wokwi-gnd", "id": "gnd1", "top": -86.4, "left": -48.6, "attrs": {} }
  ],
  "connections": [
    [ "nano:6", "ring6:DIN", "green", [ "v0" ] ],
    [ "ring6:VCC", "ring8:VCC", "red", [ "v0" ] ],
    [ "ring8:VCC", "ring10:VCC", "red", [ "v0" ] ],
    [ "ring10:VCC", "ring12:VCC", "red", [ "v0" ] ],
    [ "ring11:VCC", "ring12:VCC", "red", [ "v0" ] ],
    [ "ring9:VCC", "ring11:VCC", "red", [ "v0" ] ],
    [ "ring7:VCC", "ring9:VCC", "red", [ "v0" ] ],
    [ "ring5:VCC", "ring7:VCC", "red", [ "v0" ] ],
    [ "ring4:VCC", "ring5:VCC", "red", [ "v0" ] ],
    [ "ring3:VCC", "ring4:VCC", "red", [ "v0" ] ],
    [ "ring3:VCC", "ring2:VCC", "red", [ "v0" ] ],
    [ "ring2:VCC", "ring1:VCC", "red", [ "v0" ] ],
    [ "vcc1:VCC", "ring1:VCC", "red", [ "v0" ] ],
    [ "ring6:GND", "gnd1:GND", "black", [ "v0", "h-38.4" ] ],
    [ "ring6:GND", "ring8:GND", "black", [ "v0" ] ],
    [ "ring8:GND", "ring10:GND", "black", [ "v0" ] ],
    [ "ring10:GND", "ring12:GND", "black", [ "v0" ] ],
    [ "ring11:GND", "ring12:GND", "black", [ "v0" ] ],
    [ "ring9:GND", "ring11:GND", "black", [ "v0" ] ],
    [ "ring7:GND", "ring9:GND", "black", [ "v0" ] ],
    [ "ring5:GND", "ring7:GND", "black", [ "v0" ] ],
    [ "ring4:GND", "ring5:GND", "black", [ "v86.4", "h86.4" ] ],
    [ "ring3:GND", "ring4:GND", "black", [ "v0" ] ],
    [ "ring3:GND", "ring2:GND", "black", [ "v0" ] ],
    [ "ring2:GND", "ring1:GND", "black", [ "v0" ] ],
    [ "ring6:DOUT", "ring8:DIN", "green", [ "v0" ] ],
    [ "ring8:DOUT", "ring10:DIN", "green", [ "v0" ] ],
    [ "ring10:DOUT", "ring12:DIN", "green", [ "v0" ] ],
    [ "ring11:DIN", "ring12:DOUT", "green", [ "v0" ] ],
    [ "ring9:DIN", "ring11:DOUT", "green", [ "v0" ] ],
    [ "ring7:DIN", "ring9:DOUT", "green", [ "v0" ] ],
    [ "ring5:DIN", "ring7:DOUT", "green", [ "v0" ] ],
    [ "ring4:DIN", "ring5:DOUT", "green", [ "v0" ] ],
    [ "ring3:DIN", "ring4:DOUT", "green", [ "v0" ] ],
    [ "ring3:DOUT", "ring2:DIN", "green", [ "v0" ] ],
    [ "ring2:DOUT", "ring1:DIN", "green", [ "v0" ] ]
  ],
  "dependencies": {}
}

Is the thing in the left top above the breadboard meant to be your external power supply? Then it's not connected to anything so no wonder it doesn't work that way.

Nothing in your code that makes me feel like it would be slow - but then you didn't define "slow" so my "fast" may very well be your "slow".

thank you very much for the help. and i think that normally this will actually work but maybe its because i work with tinkercad that they cant simulate this and don't turn on. because even when they are connected directly there is nothing. but when i connect them to the arduino they do work but i think they go slower than that i have programmed.

It is good to hear it works on the Arduino!

I think the Tinkercad simulator makes you "start" the simulator twice... that is to say in tinkercad, your "start simulation" then you press the "play" button.

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