銚子高校WS 0921

arduinoをwebで動かす

https://wokwi.com/projects/new/arduino-uno

diaglam.json

{
  "version": 1,
  "author": "Anonymous maker",
  "editor": "wokwi",
  "parts": [
    { "type": "wokwi-arduino-uno", "id": "uno", "top": 48.6, "left": -10.2, "attrs": {} },
    { "type": "wokwi-led", "id": "led1", "top": -70.8, "left": 215, "attrs": { "color": "red" } },
    {
      "type": "wokwi-pushbutton",
      "id": "btn2",
      "top": -61,
      "left": 76.8,
      "attrs": { "color": "white" }
    }
  ],
  "connections": [
    [ "led1:C", "uno:GND.1", "green", [ "v48", "h-124.4" ] ],
    [ "btn2:1.l", "uno:GND.1", "green", [ "h-19.2", "v67.2", "h47.7" ] ],
    [ "btn2:2.r", "uno:8", "green", [ "h0" ] ],
    [ "uno:7", "led1:A", "green", [ "v-28.8", "h61.2" ] ]
  ],
  "dependencies": {}
}

変数と演算

void setup() {
  Serial.begin(115200);

  int count = 10;
 
  bool status;
  status = count > 10;
  Serial.println(status);


  count = 22;
  Serial.println(count);
  count = 10 * 10;
  Serial.println(count);
  count = 10 - 10;
  Serial.println(count);
  count = 20 / 3;
  Serial.println(count);
  count = 20 % 3;
  Serial.println(count);
}

void loop() {
}

arduinoを使ったプログラミング

const int LED = 7;
const int SW = 8;

void setup() {
  Serial.begin(115200);
  pinMode(LED, OUTPUT);
  pinMode(SW, INPUT_PULLUP);
  digitalWrite(LED, LOW);
}

void loop() {
  bool input = digitalRead(SW);
  // ボタンが押された場合
  if (input == false) {
    Serial.print("pushed!\n");
    blink(5);
  }
}

void blink(int times) {
  // timesの値に合わせて点滅
  for(int i=0;i<times;i++){
    digitalWrite(LED, HIGH);
    delay(250);
    digitalWrite(LED,LOW);
    delay(250);
  }
}

事後アンケート

アンケート