<?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>
									Having some issues with my coding - Arduino				            </title>
            <link>https://www.tweaking4all.com/forum/arduino/having-some-issues-with-my-coding/</link>
            <description>Tweaking4All.com Discussion Board</description>
            <language>en-US</language>
            <lastBuildDate>Mon, 15 Jun 2026 20:45:04 +0000</lastBuildDate>
            <generator>wpForo</generator>
            <ttl>60</ttl>
							                    <item>
                        <title>RE: Having some issues with my coding</title>
                        <link>https://www.tweaking4all.com/forum/arduino/having-some-issues-with-my-coding/#post-5026</link>
                        <pubDate>Wed, 09 Aug 2023 11:38:38 +0000</pubDate>
                        <description><![CDATA[Let me see if I can help ... so first of all you&#039;ll need to decide what library you&#039;re going to be using - FastLED of NeoPixel.In your code you use both which will most likely cause conflict...]]></description>
                        <content:encoded><![CDATA[<p>Let me see if I can help ... so first of all you'll need to decide what library you're going to be using - FastLED of NeoPixel.<br />In your code you use both which will most likely cause conflicts and issues.</p>
<p>Of these 2 lines, remove one of them (I'd keep the FastLED library - better, more mature and faster, and some of your code seems to be using FastLED stuff):</p>
<pre contenteditable="false">#include "FastLED.h"
#include &lt;Adafruit_NeoPixel.h&gt;</pre>
<p>Next problem is that every (standard) Arduino code has two major functions (see also <a title="Arduino Course - Chapter 1" href="https://www.tweaking4all.com/hardware/arduino/arduino-programming-course/arduino-programming-part-1/" target="_blank" rel="noopener">my beginners course</a> where you can find some of the basics).</p>
<p>One to initialize things:</p>
<pre contenteditable="false">void setup (
...
}</pre>
<p>and one loop dat keeps repeating</p>
<pre contenteditable="false">void loop (
...
}</pre>
<p>That last one seem to be missing so nothing will really happen with your code.<br />In that loop you'll probably want to call your "<strong>switchInput</strong>" function, so the Arduino keeps looking at the switches.</p>
<p>Probably something like this (assuming PIN0, PIN1 and PIN2 are switches):</p>
<pre contenteditable="false">void loop {
  switchInput(PIN_SWITCH1, PIN_SWITCH2, PIN_SWITCH3);
}</pre>
<p>Ask you can see, I renamed the defined pins to a more meaning full and less confusing name - good habit to learn over time as it makes your code easier to read and fix.</p>
<p>Next you have a function (<strong>RunningLights</strong>) defined in a function which is not a good thing to do.<br />Taking this function definition out of the other function, comes with an issues since it asks for red, green and blue values, which are nowhere found (replaced them with "??").</p>
<p>Since we're using FastLED, the "conversion" function (between FastLED and NeoPixel - eg. ShowStrip) are no longer needed and you can use the FastLED counter part.</p>
<p> </p>
<p>Some basic cleanup makes it look like this but more needs to be done to make this more useful - hope it helps 😊 </p>
<p>Note: <strong>untested</strong>, no warranty so you computer may explode 😉 -- and <strong>it will fail</strong> when you try to compile it because of the missing parameter values of "<strong>RunningLights</strong>". So it still needs work!</p>
<pre contenteditable="false">#include "FastLED.h"

# LEDs
#define NUM_LEDS 100
#define PIN_LEDS 13
#define CHIPSET WS2811
#define BRIGHTNESS 200
CRGB leds;

# switches
#define PIN_SWITCH1 11
#define PIN_SWITCH2 10
#define PIN_SWITCH3 9
#define ON 1
#define OFF 0


void setup() {
  FastLED.addLeds&lt;CHIPSET, PIN_LEDS&gt;(leds, NUM_LEDS);
  FastLED.setBrightness(BRIGHTNESS);
  FastLED.clear();
  FastLED.show();
}

void loop {
  switchInput(PIN_SWITCH1, PIN_SWITCH2, PIN_SWITCH3);
}

void switchInput(int inputOne, int inputTwo, int inputThree) {
  if (digitalRead(inputOne) == ON &amp;&amp; digitalRead(inputTwo) == OFF &amp;&amp; digitalRead(inputThree) == OFF) {
    for (int i = 0; i &lt; NUM_LEDS; i++)
    leds = CRGB::Red;
    FastLED.show();
  }
  
  if (digitalRead(inputOne) == OFF &amp;&amp; digitalRead(inputTwo) == ON &amp;&amp; digitalRead(inputThree) == OFF) {
    for (int i = 0; i &lt; NUM_LEDS; i++)
    leds = CRGB::Green;
    FastLED.show();
  }
  
  if (digitalRead(inputOne) == OFF &amp;&amp; digitalRead(inputTwo) == OFF &amp;&amp; digitalRead(inputThree) == ON) {
    RunningLights( ??, ??, ?? ); 
  }
}    

void RunningLights(byte red, byte green, byte blue, int WaveDelay) {
  int Position=0;

  for(int j=0; j&lt;NUM_LEDS*2; j++)
  {
    Position++; // = 0; //Position + Rate;
    for(int i=0; i&lt;NUM_LEDS; i++) {
      // sine wave, 3 offset waves make a rainbow!
      //float level = sin(i+Position) * 127 + 128;
      //setPixel(i,level,0,0);
      //float level = sin(i+Position) * 127 + 128;
      setPixel(i,((sin(i+Position) * 127 + 128)/255)*red,
                 ((sin(i+Position) * 127 + 128)/255)*green,
                 ((sin(i+Position) * 127 + 128)/255)*blue);
    }
 
    FastLED.show();
    delay(WaveDelay);
}


void setPixel(int Pixel, byte red, byte green, byte blue) {
  leds.r = red;
  leds.g = green;
  leds.b = blue;
}

void setAll(byte red, byte green, byte blue) {
  for(int i = 0; i &lt; NUM_LEDS; i++ ) {
    setPixel(i, red, green, blue);
   }
   
  FastLED.show();
}</pre>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/arduino/">Arduino</category>                        <dc:creator>Hans</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/arduino/having-some-issues-with-my-coding/#post-5026</guid>
                    </item>
				                    <item>
                        <title>Having some issues with my coding</title>
                        <link>https://www.tweaking4all.com/forum/arduino/having-some-issues-with-my-coding/#post-5025</link>
                        <pubDate>Tue, 08 Aug 2023 14:41:23 +0000</pubDate>
                        <description><![CDATA[I have never worked with code or anything like it until about a month and a half ago. I am writing this code to be triggered by inputs to turn specific light sequences on. Any help in what I...]]></description>
                        <content:encoded><![CDATA[<p>I have never worked with code or anything like it until about a month and a half ago. I am writing this code to be triggered by inputs to turn specific light sequences on. Any help in what I have wrong would be greatly appreciated! I am going to copy what I have here and hopefully someone can point out what I have wrong and help me fix it.</p>
<div>
<div>
<pre contenteditable="false">#include "FastLED.h"
#include &lt;Adafruit_NeoPixel.h&gt;
#define NUM_LEDS 100
#define DATA_PIN0 11
#define DATA_PIN1 10
#define DATA_PIN2 9
#define DATA_PIN3 13
#define CHIPSET WS2811
#define BRIGHTNESS 200
#define ON 1
#define OFF 0
CRGB leds;


void setup() {
  FastLED.addLeds&lt;CHIPSET, DATA_PIN3&gt;(leds, NUM_LEDS);
  FastLED.setBrightness(BRIGHTNESS);
  FastLED.clear();
  FastLED.show();
}


void switchInput(int inputOne, int inputTwo, int inputThree) {
  if (digitalRead(inputOne) == ON &amp;&amp; digitalRead(inputTwo) == OFF &amp;&amp; digitalRead(inputThree) == OFF) {
        for (int i = 0; i &lt; NUM_LEDS; i++)
        leds = CRGB::Red;
        FastLED.show();
  }
  if (digitalRead(inputOne) == OFF &amp;&amp; digitalRead(inputTwo) == ON &amp;&amp; digitalRead(inputThree) == OFF) {
        for (int i = 0; i &lt; NUM_LEDS; i++)
        leds = CRGB::Green;
        FastLED.show();
    }
  if (digitalRead(inputOne) == OFF &amp;&amp; digitalRead(inputTwo) == OFF &amp;&amp; digitalRead(inputThree) == ON) {
   void RunningLights(byte red, byte green, byte blue, int WaveDelay) {
   int Position=0;
 
   for(int j=0; j&lt;NUM_LEDS*2; j++)
   {
      Position++; // = 0; //Position + Rate;
      for(int i=0; i&lt;NUM_LEDS; i++) {
        // sine wave, 3 offset waves make a rainbow!
        //float level = sin(i+Position) * 127 + 128;
        //setPixel(i,level,0,0);
        //float level = sin(i+Position) * 127 + 128;
        setPixel(i,((sin(i+Position) * 127 + 128)/255)*red,
                   ((sin(i+Position) * 127 + 128)/255)*green,
                   ((sin(i+Position) * 127 + 128)/255)*blue);
      }
     
      showStrip();
      delay(WaveDelay);
  }
}    
    void showStrip() {
     #ifdef ADAFRUIT_NEOPIXEL_H
     // NeoPixel
     strip.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 setAll(byte red, byte green, byte blue) {
     for(int i = 0; i &lt; NUM_LEDS; i++ ) {
     setPixel(i, red, green, blue);
     }
     showStrip();
     }
  }
}</pre>
</div>
</div>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/arduino/">Arduino</category>                        <dc:creator>Anonymous</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/arduino/having-some-issues-with-my-coding/#post-5025</guid>
                    </item>
							        </channel>
        </rss>
		