Pillar  Zuo
Published

Grove Arduino Library for Kendryte K210

Running Arduino library with K210-based board.

EasyProtip44

Things used in this project

Hardware components

Seeed MAix BiT
×1
Grove - OLED Display 1.12'' V2
Seeed Grove - OLED Display 1.12'' V2
×1
Grove - PIR Motion Sensor
Seeed Grove - PIR Motion Sensor
×1
Grove - Ultrasonic Ranger
Seeed Grove - Ultrasonic Ranger
×1
Grove - Relay
Seeed Grove - Relay
×1
Grove - WS2813 RGB LED Strip Waterproof - 60 LED/m - 1m
Seeed Grove - WS2813 RGB LED Strip Waterproof - 60 LED/m - 1m
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Breadboard, 270 Pin
Breadboard, 270 Pin

Story

Read more

Code

developing kendryte-standalone-sdk with Arduino Library

C/C++
ArduinoCore-k210 is also supported as a normal IDE. For example, when developing kendryte-standalone-sdk, you also can use the Arduino Library WS2812FX. This way you can run all the kendryte-standalone-demo in the Arduino IDE.
#include <WS2812FX.h>

#define LED_COUNT 32
#define LED_PIN 13

#define TIMER_MS 5000

// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
//   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
WS2812FX ws2812fx = WS2812FX(LED_COUNT, LED_PIN, NEO_RGB + NEO_KHZ800);

unsigned long last_change = 0;
unsigned long now = 0;

extern "C" {
#include <stdio.h>
#include <unistd.h>
#include "fpioa.h"
#include "gpiohs.h"
#include "sysctl.h"

uint32_t irq_flag;

#define PIN_LED 25
#define PIN_KEY 26

#define GPIO_LED 3
#define GPIO_KEY 2

uint32_t g_count;

int irq_gpiohs2(void* ctx)
{
    irq_flag = gpiohs_get_pin(GPIO_KEY);

    printf("IRQ The PIN is %d\n", irq_flag);

    uint32_t *tmp = (uint32_t *)(ctx);
    printf("count is %d\n", (*tmp)++);

    if (!irq_flag)
        gpiohs_set_pin(GPIO_LED, GPIO_PV_LOW);
    else
        gpiohs_set_pin(GPIO_LED, GPIO_PV_HIGH);
    return 0;
}

int main(){
#define NOFREERTOS 1

  plic_init();
  sysctl_enable_irq();

  fpioa_set_function(PIN_LED, FUNC_GPIOHS3);
  gpiohs_set_drive_mode(GPIO_LED, GPIO_DM_OUTPUT);
  gpio_pin_value_t value = GPIO_PV_HIGH;
  gpiohs_set_pin(GPIO_LED, value);

  fpioa_set_function(PIN_KEY, FUNC_GPIOHS2);
  gpiohs_set_drive_mode(GPIO_KEY, GPIO_DM_INPUT_PULL_UP);
  gpiohs_set_pin_edge(GPIO_KEY, GPIO_PE_BOTH);

  gpiohs_irq_register(GPIO_KEY, 1, irq_gpiohs2, &g_count);


  ws2812fx.init();
  ws2812fx.setBrightness(255);
  ws2812fx.setSpeed(1000);
  ws2812fx.setColor(0x007BFF);
  ws2812fx.setMode(FX_MODE_STATIC);
  ws2812fx.start();
  while(1){
      now = millis();
    
      ws2812fx.service();
    
      if(now - last_change > TIMER_MS) {
        ws2812fx.setMode((ws2812fx.getMode() + 1) % ws2812fx.getModeCount());
        last_change = now;
      }    
    }
 return 0; 
 }
}

Credits

Pillar  Zuo

Pillar Zuo

0 projects • 0 followers

Comments

Add projectSign up / Login