Compared to the Picoclick-C3T the C3 is optimized to be used with the Arduino framework which is probably great for most users. Of course the ESP-IDF can still be used for the C3, but the flashing configurations don't have to be changed like for the C3T.
I'm always using Visual Studio Code with the PlatformIO plugin to flash my microcontrollers. If you haven't worked with it yet I can recommend going through the quick start guide by Rui Santos (RandomNerdTutorials).
If you have set it up correctly you can simply start by adding a project folder to your workspace. In doing so you have to right click somewhere in the workspace and select "Add Folder to Workspace...". A great way to start is by choosing one of the Picoclick-C3 projects from my Github repository. Once added, the project structure should look like the structure shown in the right image. The two most important files are the main.cpp which is the file where all the project code goes in and the platform.ini which is the configuration file of the project. Latter defines what processor you are using, which COM-port the Picoclick is connected to and other build settings.
platform.ini
The project configuration file of your Picoclick project can look like this, where a ; defines a comment. If the upload_port and monitor_port are commented out, PlatformIO will assign these ports automatically. If only one device is connected to your computer this will work fine.
The lip_deps defines which libraries and which versions are used. The FastLED library is used to control the APA102 LEDs and thus should be present in every project. If using other libraries these should be added to this list.
config.h
The config.h file is not neccessary but will clean up your main project file a bit. It defines the hardware definitions of the Picoclick and thus are always the same. Furthermore it contains some useful FastLED things and the function for reading the battery voltage. This file can be included by adding the line #include "config.h" in your main project and it should look like this:
If the config.h file isn't used you have to add all these pin definitions in the top of your main.cpp file.
main.cpp
The main project file includes the code for your board and is similar to the .ino file for the Arduino IDE.
Following code is a basic example which will change the color of both LEDs if the button is pressed. If the button is press & hold for one second or the button isn't pressed for 10 seconds the Picoclick will turn off by entering the deep sleep mode with esp_deep_sleep_start(). Again, this won't enter the deep sleep of the ESP32 because the Picoclick will loose power beforehand due to the latching circuit.
#include <Arduino.h>
#include <WiFi.h>
#include <FastLED.h>
#include "config.h"
int color = 0;
void setup(){
pinMode(BUTTON_PIN, INPUT);
pinMode(ADC_ENABLE_PIN, OUTPUT);
pinMode(ADC_PIN, INPUT);
analogReadResolution(12);
digitalWrite(ADC_ENABLE_PIN, HIGH);
btStop();
WiFi.mode(WIFI_OFF);
FastLED.addLeds<APA102, APA102_SDI_PIN, APA102_CLK_PIN, BGR>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(180);
delay(50);
set_fastled(CRGB::Blue);
delay(500);
}
unsigned long t_last_press = 0;
void loop() {
// Change color if the button is pressed. After the eight click, generate random color. Press & hold for 1 second to turn off the device.
// Device will turn off after 10 seconds not pressing the button.
if(digitalRead(BUTTON_PIN) == 1){
color++;
CRGB tmp_color = CRGB::Black;
if(color == 1) tmp_color = CRGB::Green;
else if(color == 2) tmp_color = CRGB::Red;
else if(color == 3) tmp_color = CRGB::Yellow;
else if(color == 4) tmp_color = CRGB::White;
else if(color == 5) tmp_color = CRGB::Orange;
else if(color == 6) tmp_color = CRGB::Aqua;
else if(color == 7) tmp_color = CRGB::HotPink;
else if(color == 8) tmp_color = CRGB::LimeGreen;
else{
int r = random(255), g = random(255), b = random(255);
tmp_color = CRGB(r, g, b);
}
set_fastled(tmp_color);
unsigned long t_pressed = millis();
while(digitalRead(BUTTON_PIN) == 1){
delay(10);
if(millis() > t_pressed + 1000){
set_fastled(CRGB::Red);
delay(1000);
esp_deep_sleep_start();
}
}
t_last_press = millis();
}
if(millis() - t_last_press > 10000){
set_fastled(CRGB::Red);
delay(1000);
esp_deep_sleep_start();
}
}