2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

全自動スリットアニメーション表示機

Last updated at Posted at 2020-12-20

スリットアニメーションとは

スリットアニメーション(スキャニメーションともいうらしい)とは、ギザギザの絵の上にスリットの入ったシートを被せて横にスライドさせることで、下の絵が動いているように見える、という目の錯覚を利用した遊びです。
以下のページに詳しく書いてあるので、そちらをどうぞ。私もここのページを参考にさせてもらいました。
https://scanimation-meijinkai.info/whatis/

image.png

作りたいもの

スリットアニメーションでアニメーションさせるには、スリットのシートをスライドさせる必要があります。
手でスライドすればいいのですが、面倒なので、モータを使って自動でスライドさせてみることにします。

作ってみた

image.png

タミヤのモーターとこれまたタミヤの「楽しい工作シリーズ」を駆使して作ってみました。
「楽しい工作シリーズ」を初めて使ってみましたが、とても便利ですね。

クランクとアームでモーターの円運動をスライドの往復運動に変えています。

以下は動かしてみた動画です。途中、PWMのduty比を変えて速度を変えています。

ソースコード

M5Stackのソースコードです。

.cpp
# include <M5Stack.h>

const double PWM_Hz = 2000;   // PWM周波数
const uint8_t PWM_level = 8; // PWM分解能 16bit(0~255)
const uint8_t PWM_CH = 1;  // チャンネル

uint32_t duty = 64;

void setup() {
  // put your setup code here, to run once:
  M5.begin();
  M5.Power.begin();

  pinMode(26, OUTPUT); 

  // チャンネルと周波数の分解能を設定
  ledcSetup(PWM_CH, PWM_Hz, PWM_level);
  //モータのピンとチャンネルの設定
  ledcAttachPin(26, PWM_CH);
  //duty比を0に設定
  ledcWrite(PWM_CH,0);
}

void loop() {
  M5.update();

  // 現在のdutyを表示
  M5.Lcd.setCursor(0,0);
  M5.Lcd.setTextColor(WHITE,BLACK);
  M5.Lcd.setTextSize(3);
  M5.Lcd.printf("duty: %03d",duty);
  
  // dutyをプラス(Max255)
  if (M5.BtnA.wasPressed())
  {
    if (duty < 255)
    {
      duty += 1;
    }

    ledcWrite(PWM_CH,duty);
  }
  // dutyをマイナス(Max0)
  else if (M5.BtnB.wasPressed())
  {
    if (duty > 0)
    {
      duty -= 1;
    }

    ledcWrite(PWM_CH,duty);
  }
  // dutyを0に(モーターを止める)
  else if (M5.BtnC.wasPressed())
  {
    ledcWrite(PWM_CH,0);
  }

  delay(10); 
}

以上です!!

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?