티스토리 뷰

OS/Banana Pi /BPI-Bit

BPI-Bit : Arduino 개발환경 구축하기

파란크리스마스 2018. 9. 21. 21:12
728x90

출처

BPI-Bit : Arduino 개발환경 구축하기

BPI-Bit는 몇가지 개발 언어가 있는데 Webduino 말고도 Arduino IDE로 개발할 수 있어서, Arduino IDE 개발환경을 구축하고 간단예제를 실행해보았습니다.

1. Arduino IDE 설치

Arduino IDE (arduino-1.8.7-windows.zip)를 다운로드받고, 설치

2. arduino-esp32 다운로드

Github 저장소(espressif / arduino-esp32)에서 arduino-esp32-master.zip 파일 다운로드

3. arduino-esp32 설치

다운로드 받은 파일 arduino-esp32-master.zip을 [Arduino IDE 설치경로]/hardware/espressif/esp32에 압축 해제

4. get 명령을 관리자 권한으로 실행

[Arduino IDE 설치경로]/hardware/espressif/esp32/tools 디렉토리에서 get 명령을 관리자 권한으로 실행 실행

5. Arduino IDE를 실행하고, 메뉴[툴] > [보드] > [NodeMCU -32S] 선택

예제 작성

//BIT NEW
//BPI - BIT test code
#include <Arduino.h>
#include <NeoPixelBus.h>

#define LEDC_CHANNEL_0 0
#define LEDC_TIMER_13_BIT 13
#define LEDC_BASE_FREQ 4500

const uint16_t PixelCount = 25;
const uint8_t PixelPin = 4;

#define colorSaturation 128
#define delay_ms 500

NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> strip(PixelCount, PixelPin);

RgbColor red(colorSaturation, 0, 0);
RgbColor green(0, colorSaturation, 0);
RgbColor blue(0, 0, colorSaturation);
RgbColor white(colorSaturation);
RgbColor black(0);
RgbColor num1(0.8 * colorSaturation, 0, 0.2 * colorSaturation);
RgbColor num2(0.5 * colorSaturation, 0, 0.5 * colorSaturation);
RgbColor num3(0.25 * colorSaturation, 0, 0.75 * colorSaturation);

HslColor hslRed(red);
HslColor hslGreen(green);
HslColor hslBlue(blue);
HslColor hslWhite(white);
HslColor hslBlack(black);

#define ledPower 2
#define BottomA 35
#define BottomB 27

int brightness = 0;
int fadeAmount = 5;

void ledcAnalogWrite(uint8_t channel, uint32_t value) {
  // calculate duty, 8191 from 2 ^ 13 - 1 (2 ^ LEDC_TIMER_13_BIT - 1)
  //value_MAX = 255
  uint32_t duty = (8191 / 255) * value;
  // write duty to LEDC
  ledcWrite(channel, duty);
}

void setup() {
  Serial.begin(115200); //Serial Port Config 115200-8-N-1
  
  Serial.println();
  Serial.println("Initializing...");
  Serial.flush();
  
  // this resets all the neopixels to an off state
  strip.Begin();
  strip.Show();
  
  pinMode(ledPower,OUTPUT);
  pinMode(BottomA, INPUT);
  pinMode(BottomB, INPUT);
  digitalWrite(ledPower, HIGH);
  
  // strip.SetPixelColor(10, blue);
  // strip.SetPixelColor(11, blue);
  // strip.SetPixelColor(12, blue);
  // strip.SetPixelColor(13, blue);
  // strip.SetPixelColor(14, red);
  // strip.Show();
  
  // delay(1000);
  
  // int i;
  // for (i = 0; i <= PixelCount - 1; i++)
  // {
  //     strip.SetPixelColor(i, black);
  //     strip.Show();
  // }
}

void loop() {
  //signel map
  if (digitalRead(BottomA) == LOW) {
    delay(10);
    if (digitalRead(BottomA) == LOW) {
      strip.SetPixelColor(16, num1);
      strip.SetPixelColor( 7, num2);
      strip.SetPixelColor(18, num3);
      strip.Show();
    } else {
      int i;
      Serial.println("Turn Off");
      for (i = 0; i <= PixelCount - 1; i++) {
        strip.SetPixelColor(i, hslBlack);
        strip.Show();
      }
    }
  }
}

예제 실행

댓글
300x250
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/03   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
글 보관함