Go Down

Topic: Quick conversion from Makerboard C+ to Arduino (Read 61 times) previous topic - next topic

xWHiiSPeRx

Hi Guys,

I know the Arduino uses a modified version of C language, but I'm struggling here. I know there will hundreds that will fix this in seconds.

I found an LED strip reaction game that is coded for MakerBoard, but wish to use it with the Arduino. Seems quite simple code, but...No matter what I do it errors on LEDStrip is not a name. Could someone please change the following code to work for me please.

My LED Strip is on data pin 2.....button I can put anywhere. Already use NeoPixel library. Maybe FastLed is needed.

Many Thanks


/*
 * Reaction game-  press the button when the moving pixel overlaps
 * the center one. Speed increases each time you succeed
 */

//Include the LEDStrip library to use the commands
#include "LEDStrip.h"

const byte numPixels = 15; //Number of pixels on a strip
const byte middlePixel = numPixels/2; //The pixel at the middle of your strip

int pixel = 0; //Position of the pixel on the strip

const int hitColor = 50; //The color of the strip when you hit the mark
const int missColor = 100; //The color of the strip when you miss the mark

int Direction = 1; //Direction of travel of the pixel

int delayTime = 300; //Starting time (in ms) between pixel movements

long timer = millis(); //Timer to control movement of pixel

/*
 * Make the LED strip object LEDStrip strip
 *  = LEDStrip(numPixels, dataPin (DI), clockPin (CI));
 */
LEDStrip strip = LEDStrip(numPixels, 13, 12);


void setup() {

  //Button
  pinMode(A5,INPUT_PULLUP);
}

void loop() {

  //If at the center pixel
  if (pixel == middlePixel){
    strip.setPixel(pixel,(hitColor+missColor)); //overlap the colors
   
    //If the button is pressed while on the center pixel
    if (digitalRead(A5) == LOW){
       delayTime= delayTime*.75; //delayTime reduced by 25%
     
      //Blink the hitColor to indicate success
      strip.setPixel(strip.ALL,hitColor);
      strip.draw();
      delay(1000);
      strip.clear();
    }
  }

  //When not on the center pixel
  if (pixel != middlePixel){
    strip.setPixel(pixel,missColor); //Set the moving pixel
    strip.setPixel(middlePixel,hitColor); //Set the center pixel

    //If button pressed when not at center
    if (digitalRead(A5) == LOW){
     
      //Blink all pixels the missColor for a second
      strip.setPixel(strip.ALL,missColor);
      strip.draw();
      delay(1000);
      strip.clear();
   
      delayTime = delayTime + 100; //Slow down the ball
    }
   }

  //Every delayTime many ms, update pixel position
  if (millis()-timer > delayTime){
    timer = millis(); //Reset the timer
    strip.setPixel(pixel,-1); //Clear previous pixel
    pixel = pixel + Direction; //Move the pixel
   
    //If at either end of the strip, change direction of travel
    if ((pixel == 0)||(pixel == numPixels-1)){
      Direction = Direction*-1;
    }
  }

  strip.draw(); //Draw what was written to the strip this loop
}

//Change the reduction to delayTime time to make the game move more
//  quickly



pert

Please do this:
  • When you encounter an error, you'll see a button on the right side of the orange bar "Copy error messages" in the Arduino IDE (or the icon that looks like two pieces of paper at the top right corner of the black console window in the Arduino Web Editor). Click that button..
  • In a forum reply here, click on the reply field.
  • Click the </> button on the forum toolbar. This will add the forum's code tags markup to your reply.
  • Press "Ctrl + V". This will paste the error between the code tags.
  • Move the cursor outside of the code tags before you add any additional text to your reply.


If the text exceeds the forum's 9000 character limit, save it to a .txt file and post it as an attachment. If you click the "Reply" button here, you will see an "Attachments and other settings" link.

Please post a link (using the chain links icon on the forum toolbar to make it clickable) to where you downloaded the LEDStrip library from. Or if you installed it using Library Manger (Sketch > Include Library > Manage Libraries in the Arduino IDE or Libraries > Library Manager in the Arduino Web Editor) then say so and state the full name of the library.

Go Up