본문 바로가기

코딩 놀이

g_code로 LED On Off [34]

CNC 수치제어 장치에서 사용하는 Gcode로아두이노 우노 D13번  LED 13번을 점멸해봅니다.

시리얼 모니터서 L1,L2 입력해봅니다..

#include <gcode.h>

#define LEDpin 13
#define NumberOfCommands 2 // 명령 두개 L1, L2

void OnLED();  // 함수선언
void OffLED();// 함수 선언


commandscallback commands[NumberOfCommands] = {{"L1",OnLED},{"L2",OffLED}}; // L1, L2 명령을 받고 실행 명령
gcode Commands(NumberOfCommands,commands); // 명령 문

void setup()
{
  Commands.begin("ok"); 
  pinMode(LEDpin, OUTPUT);
}

void loop() 
{
  Commands.available();
}

void OnLED()
{
  digitalWrite(LEDpin, HIGH);
}

void OffLED()
{
  digitalWrite(LEDpin, LOW);
}

 

 

 

 

https://github.com/tinkersprojects/G-Code-Arduino-Library