Navigation

    M5Stack Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. trrevvorr
    T
    • Continue chat with trrevvorr
    • Start new chat with trrevvorr
    • Flag Profile
    • Profile
    • Following
    • Followers
    • Blocks
    • Topics
    • Posts
    • Best
    • Groups
    Save
    Saving

    trrevvorr

    @trrevvorr

    1
    Reputation
    3
    Posts
    616
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    trrevvorr Follow

    Posts made by trrevvorr

    • RE: M5Stamp C3 programming examples

      I updated @auct's code to include the built in button as well:

      #include <Adafruit_NeoPixel.h>
      
      #define BUTTON_PIN 3
      #define PIXEL_PIN 2
      #define NUM_PIXELS 1
      
      Adafruit_NeoPixel pixel(NUM_PIXELS, PIXEL_PIN, NEO_GRBW + NEO_KHZ400);
      bool currentButtonPressed = false;
      
      void setup()
      {
         // set up serial out
        Serial.begin(115200);
      
        // set up neopixel
        pixel.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
        pixel.clear(); // Set pixel colors to 'off'
        pixel.show();
        
        // set up GPIO
        pinMode(BUTTON_PIN, INPUT_PULLUP);
      
        // initial button pressed state
        setPixelToCurrentButtonState();
      }
      
      void loop()
      {
        // read button state (LOW when pressed)
        bool newButtonPressed = digitalRead(BUTTON_PIN) == LOW;
        setPixelStateIfChanged(newButtonPressed);
      
        delay(10); // debounce
      }
      
      void setPixelStateIfChanged(bool newButtonPressed) {
        if (newButtonPressed != currentButtonPressed) {
          currentButtonPressed = newButtonPressed;
          setPixelToCurrentButtonState();
        }
      }
      
      void setPixelToCurrentButtonState() {
        if (currentButtonPressed) {
          Serial.println("turning LED blue");
          pixel.setPixelColor(0, pixel.Color(0, 0, 128));
          pixel.show(); 
        } else {
          Serial.println("turning LED red");
          pixel.setPixelColor(0, pixel.Color(128, 0, 0));
          pixel.show(); 
        }
      }
      
      posted in Modules
      T
      trrevvorr
    • RE: M5Stamp C3 programming examples

      @auct Thank you! After adding the Adafruit neopixel library to the arduino IDE, this worked great!

      I'll also note that I had issues flashing code to the C3 with my Mac (running OSX Catalina with updated drivers) but using a Windows machine fixed that issue.

      posted in Modules
      T
      trrevvorr
    • RE: M5Stamp C3 programming examples

      These examples would be very much appreciated. I've been having trouble getting ESP-IDF or Arduino IDE to flash any code to my M5Stamp-C3 since there are virtually no examples of how to do this on the internet.

      posted in Modules
      T
      trrevvorr