17/07/2567

ปีการศึกษา 2567 Arduino (7segment Clock Display)

📣ความรู้ไปประยุกต์ใช้อุปกรณ์อิเล็กทรอนิกส์เพื่อสร้างสรรค์เป็นโครงงานตามที่โจทย์กำหนดได้วงจร

📣ความรู้ไปประยุกต์ใช้อุปกรณ์อิเล็กทรอนิกส์เพื่อสร้างสรรค์เป็นโครงงานตามที่โจทย์กำหนดได้คำสั่งเขียน 


#include "Adafruit_LEDBackpack.h"

#include <IRremote.h>

int button = 0;

Adafruit_7segment led_display1 = Adafruit_7segment();

//    0   1   2

//    4   5   6

//    8   9  10

//   12  13  14

//   16  17  18

//   20  21  22

//   24  25  26

int mapCodeToButton(unsigned long code) {

  if ((code & 0x0000FFFF) == 0x0000BF00) {

    code >>= 16;

    if (((code >> 8) ^ (code & 0x00FF)) == 0x00FF) {

      return code & 0xFF;

    }

  }

  return -1;

}


int readInfrared() {

  int result = -1;

 

  if (IrReceiver.decode()) {

    unsigned long code = IrReceiver.decodedIRData.decodedRawData

    result = mapCodeToButton(code);

    IrReceiver.resume();

  }

  return result;

}


void setup()

{

  led_display1.begin(112);

  IrReceiver.begin(2);

  led_display1.println("----");

  led_display1.writeDisplay();

}

void loop()

{

  button = readInfrared();

  if (button >= 0) {

    led_display1.println(button);

    led_display1.writeDisplay();

  }

  delay(10); 

}



ไม่มีความคิดเห็น:

แสดงความคิดเห็น

ครูเต้ง เทคโนฯ