Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uploading Sketch to Trinket #1

Open
GamerGoblin opened this issue Oct 15, 2015 · 2 comments
Open

Uploading Sketch to Trinket #1

GamerGoblin opened this issue Oct 15, 2015 · 2 comments

Comments

@GamerGoblin
Copy link

Hello Timpear,

Firstly, awesome tutorial on the NeoCandle, very impressive! :)

Secondly, time for a stupid question;

How did you manage to upload the NeoCandle Sketch to the Trinket? I have tried multiple different things in the Arduino IDE but nothing will work, it keeps coming up with a ControlP5 "author" not found error.

So I consulted the creator of the ControlP5 library and he seemed to think that it would only run in Processing and the ControlP5 library wouldn't be compatible with the Arduino IDE. Also that it would not be capable of uploading a Sketch using the ControlP5 library to a piece of hardware like the Trinket.

I wanted to disagree, but I thought I would consult you first.

Just to confirm, the ControlP5 library is used in this sketch or have I possibly setup my IDE wrong?

Any help or assistance you can provided would be greatly appreciated.

Kind Regards,

Michael

@timpear
Copy link
Owner

timpear commented Oct 15, 2015

Thanks!

I've found uploading to the Trinket to be a little tricky on occasion -- sometimes unplugging and replugging is required, and also don't forget to push the programmer button on the Trinket to put it into programming mode. But the key thing is using the Adafruit Arduino IDE, NOT the regular Arduino IDE. Follow links here: https://learn.adafruit.com/introducing-trinket/setting-up-with-arduino-ide

I hope that helps.

@BulldogLowell
Copy link

BulldogLowell commented Dec 16, 2016

Hey Tim,

I've been using this bit of code for little votives around the house (started with a nightlight for my daughter. Using it for a Particle Photon application, I wasn't happy with the blocky-ness of the code, so I made a little class. Since you inspired it, I thought to share it with you:

#include "neopixel.h"

enum CandleStates{
  BURN_CANDLE,
  FLICKER_CANDLE,
  FLUTTER_CANDLE,
  MODES_MAX_CANDLE
};

enum PixelSelect{
  EVERY_PIXEL,
  SINGLE_PIXEL,
};

class Candle : public Adafruit_NeoPixel
{
  public:
    Candle(uint16_t count, uint8_t pin, uint8_t type);
    Candle(uint16_t count, uint8_t pin, uint8_t type, PixelSelect pixel, uint32_t pixNum = 0);
    ~Candle(){};
    void update();

  private:
    bool fire(uint8_t greenDropValue, uint32_t cycleTime);

    PixelSelect _pixelMode = EVERY_PIXEL;
    uint32_t _pixNum = 0;
    CandleStates _mode;
    uint32_t _lastModeChange;
    uint32_t _modeDuration;

    uint8_t _redPx = 255;
    uint8_t _bluePx = 10; //10 for 5v, 15 for 3.3v
    uint8_t _grnHigh = 100; //110-120 for 5v, 135 for 3.3v
    uint8_t _grnPx = 100;

    uint32_t _lastBurnUpdate = 0;
    int _direction = 1;
};

Candle::Candle(uint16_t count, uint8_t pin, uint8_t type) : Adafruit_NeoPixel(count, pin, type)
{
  randomSeed(Time.now() + micros());
  _mode = BURN_CANDLE;
}

Candle::Candle(uint16_t count, uint8_t pin, uint8_t type, PixelSelect pixel, uint32_t pixNum) : Adafruit_NeoPixel(count, pin, type)
{
  _pixelMode = pixel;
  _pixNum = pixNum;
}

void Candle::update()
{
  if(millis() - _lastModeChange > _modeDuration)
  {
    _mode = static_cast<CandleStates>(random(MODES_MAX_CANDLE));
    _modeDuration = random(1000, 8000);
    _lastModeChange = millis();
    //Serial.printlnf("New state: %d\tTime: %d", static_cast<int>(_mode), _modeDuration);
  }
  switch(_mode)
  {
    case BURN_CANDLE:
      this->fire(10, 120);
      break;
    case FLICKER_CANDLE:
      this->fire(15, 120);
      break;
    case FLUTTER_CANDLE:
      this->fire(30, 120);
      break;
  };
}

bool Candle::fire(uint8_t greenDropValue, uint32_t cycleTime)
{
  int currentMillis = millis();
  if(currentMillis - _lastBurnUpdate > (cycleTime / greenDropValue / 2))
  {
    _grnPx = constrain(_grnPx += _direction, _grnHigh - greenDropValue, _grnHigh);
    if(_grnPx == _grnHigh - greenDropValue or _grnPx == _grnHigh)
    {
      _direction *= -1;
    }
    switch (_pixelMode)
    {
      case EVERY_PIXEL:
        for(int i = 0; i < this->numPixels(); i++)
        {
          this->setPixelColor(i, _grnPx, _redPx, _bluePx);
        }
        break;
      case SINGLE_PIXEL:
        this->setPixelColor(_pixNum, _grnPx, _redPx, _bluePx);
        break;
    }
    this->show();
    _lastBurnUpdate = currentMillis;
  }
}

#define PIXEL_COUNT 2
#define PIXEL_PIN D2
#define PIXEL_TYPE WS2812B    // I'M USING GRB WS2821B's here

Candle candle = Candle(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE, SINGLE_PIXEL);

void setup(void)
{
  Serial.begin(115200);
  pinMode(D7, OUTPUT);
  candle.begin();
  candle.show();
  Serial.println("Started program");
}

void loop(void)
{
  candle.update();
  static uint32_t lastFlashMillis = 0;
  if(millis() - lastFlashMillis > 250)
  {
    digitalWrite(D7, !digitalRead(D7));
    lastFlashMillis = millis();
  }
}

thanks so much for the initial work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants