lundi 22 mai 2017

random selection of input pin

I'm Jo I'm rather new at this and have hit a brick wall on somthing relatively simple

I have the following code attached

I would like input pin 8 to make a random selection of input pins 1-7 and have no idea to write it

Please educate me

Many thanks

//          SONIC PROTOTYPE CODE         

//      Written by a complete amateur so take good care!

//  This is the code that will go in to my sonic screwdriver
//  Hardware includes Adafruit Feather 32U4, Music maker feather wing with amp Adafruit NeoPixel stick
//  



#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif

#define PIN A1

const int sw1 = 2;     // This sets the name of the pins
const int sw2 = 3;
const int sw3 = 5;
const int sw4 = 6;
const int sw5 = 9;
const int sw6 = 10;
const int sw7 = 11;
const int sw8 = 12;

                    struct RGB {          //for fire this could posibly reside elsewhere in the script but I'm not too sure where
                    byte r;
                    byte g;
                    byte b;
                    };

                    RGB flameColors[] = {
                    //  { 226, 121, 35},  // Orange flame   /// select what colour fire you want here 
                    //  { 158, 8, 148},   // Purple flame 
                    //  { 74, 150, 12},   // Green flame
                    //  { 226, 15, 30}    // Red flame
                        { 15,50,148}      //Blue flame
                    };
                    //  Number of flame colors
                    int NUMBER_OF_COLORS = sizeof(flameColors) / sizeof(RGB);

                    //  Tracks the current color
                    int currentColorIndex = 0;

                    //  The button pin
                    const int buttonPin = 2;

                    //  Variable for reading the pushbutton status
                    int buttonState = 0;         

                    //  Tracking if it's ok to shift colors or not
                    bool okToChangeColors = true;




                    float redStates[8];               // I added these for twinkle
                    float blueStates[8];
                    float greenStates[8];
                    float fadeRate = 0.96;           

                    int totalLEDs = 8;                // added for tardis
                    int ledFadeTime = 5;


  Adafruit_NeoPixel strip = Adafruit_NeoPixel(8, A1, NEO_GRB + NEO_KHZ800);

    // IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
    // pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
    // and minimize distance between Arduino and first pixel.  Avoid connecting
    // on a live circuit...if you must, connect GND first.


    void setup() 
  {

       pinMode(sw1, INPUT_PULLUP);    // the pins for your pull low are set here
       pinMode(sw2, INPUT_PULLUP);
       pinMode(sw3, INPUT_PULLUP);
       pinMode(sw4, INPUT_PULLUP);
       pinMode(sw5, INPUT_PULLUP);
       pinMode(sw6, INPUT_PULLUP);
       pinMode(sw7, INPUT_PULLUP);
       pinMode(sw8, INPUT_PULLUP);

      strip.begin();
      strip.show(); // Initialize all pixels to 'off'
    }

    void loop() 
  {
      // Some example procedures showing how to display to the pixels:
     // if (digitalRead(sw1) == LOW) colorWipe(strip.Color(255, 0, 0), 50, sw1); // Red
     // if (digitalRead(sw7) == LOW) colorWipe(strip.Color(0, 255, 0), 50, sw7); // Green
      if (digitalRead(sw2) == LOW) skip(150, 0, 150, 250, sw2);                                                                                                                                     
      if (digitalRead(sw1) == LOW) BouncingBalls(0, 0, 255, 3, sw1);                            
      if (digitalRead(sw3) == LOW) twinkle (sw3);                                       
    //  if (digitalRead(sw3) == LOW) colorWipe(strip.Color(0, 0, 255), 50, sw3); // Blue
    //  if (digitalRead(sw4) == LOW) theaterChase(strip.Color(127, 127, 127), 50, sw4); // White
    //  if (digitalRead(sw5) == LOW) theaterChase(strip.Color(127, 0, 0), 50, sw5); // Red
     // if (digitalRead(sw6) == LOW) theaterChase(strip.Color(0, 0, 127), 50, sw6); // Blue
      if (digitalRead(sw4) == LOW) rainbow(20, sw4);
      if (digitalRead(sw5) == LOW) rainbowCycle(20, sw5);
      if (digitalRead(sw6) == LOW) fire (sw6);
      if (digitalRead(sw7) == LOW) theaterChaseRainbow(50, sw7);
      //if (digitalRead(sw8) == LOW) tardis(sw8);
                  if (digitalRead(sw8) == LOW) scanner (sw8);                                                                                     
    }




Aucun commentaire:

Enregistrer un commentaire