博文

目前显示的是 三月, 2023的博文

[06.) BLOG POST: INPUT/OUTPUT (INTERACTIVE OBJECT)]

图片
                                               https://youtu.be/ANPTbi9osF4 This work comes from a story in ancient China, which took place during the Shang and Zhou periods of history and legend. King Zhou of Shang was tyrannical and King Wen of Zhou was determined to overthrow the tyranny. Tai Gong Jiang Ziya was ordered by his master to go down to the world to help King Wen. But Jiang Ziya felt that he was half a hundred years old and had no friendship with King Wen, so it was difficult for him to gain his appreciation. So on his way back to the capital, he fished on the side of the river with a straight hook without bait. The hook was curved, but Jiang Ziya used a straight hook (which could not be called a hook) without bait. When King Wen saw it, he thought it was a strange man, so he took the initiative to talk to him and found it was a really useful talent, so he recruited him into his tent. Later, Jiang Ziya helped King Wen and his son overthrow King Zhou of the Shang Dynasty a

A2.3.3

图片
 This is a kitten fishing toy, which consists of a button and a servo motor. The idea came from the last blog, and was adapted. When the button is pressed the kitten's fishing rod will be retracted, and when pressed again the rod will be lowered. <textarea> #include <Servo.h> const int BUTTON_PIN = 7;  const int SERVO_PIN  = 9;  Servo servo;  int angle = 0;          int lastButtonState;    int currentButtonState;  void setup() {   Serial.begin(9600);                   pinMode(BUTTON_PIN, INPUT_PULLUP);    servo.attach(SERVO_PIN);             servo.write(angle);   currentButtonState = digitalRead(BUTTON_PIN); } void loop() {   lastButtonState    = currentButtonState;        currentButtonState = digitalRead(BUTTON_PIN);    if(lastButtonState == HIGH && currentButtonState == LOW) {     Serial.println("The button is pressed");         if(angle == 0)       angle = 90;     else     if(angle == 90)       angle = 0;     servo.write(angle);   } } </textarea&