1
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?

XIAO ESP32C6+SSD1306、円弧を書いて遊ぶ。(キラキラをかえせ(何の事?

Last updated at Posted at 2025-05-21

いろいろ注意

  • 過去ログを見よ!!!
  • 3.2.0
  • いろいろ 7話、おもしろかった(何の今期アニメ(キーワードは、キラキラ
  • いろいろ 数学パズルの愛好家の方がマイコン系より、多い事がわかった。(実装系に人気がない
  • 平方根を使うより塗り潰しのアルゴリズムの方が速いか?

結果

image_original(38).jpg

プログラム



//OLED_SSD1331_enko2_XIAO_ESP32C6


//ヘッダーファイル
#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>


//定義
#define SCREEN_WIDTH 128     // OLED display width, in pixels
#define SCREEN_HEIGHT 64     // OLED display height, in pixels
#define OLED_RESET -1        // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C  ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);


int i_sqrt(int n){
    //30
    if( n > (32*32-1) ) return 32;
    if( n > (31*31-1) ) return 31;
    if( n > (30*30-1) ) return 30;
    //20
    if( n > (29*29-1) ) return 29;
    if( n > (28*28-1) ) return 28;
    if( n > (27*27-1) ) return 27;
    if( n > (26*26-1) ) return 26;
    if( n > (25*25-1) ) return 25;
    if( n > (24*24-1) ) return 24;
    if( n > (23*23-1) ) return 23;
    if( n > (22*22-1) ) return 22;
    if( n > (21*21-1) ) return 21;
    if( n > (20*20-1) ) return 20;
    //10
    if( n > (19*19-1) ) return 19;
    if( n > (18*18-1) ) return 18;
    if( n > (17*17-1) ) return 17;
    if( n > (16*16-1) ) return 16;
    if( n > (15*15-1) ) return 15;
    if( n > (14*14-1) ) return 14;
    if( n > (13*13-1) ) return 13;
    if( n > (12*12-1) ) return 12;
    if( n > (11*11-1) ) return 11;
    if( n > (10*10-1) ) return 10;
    //1
    if( n > (9*9-1) ) return 9;
    if( n > (8*8-1) ) return 8;
    if( n > (7*7-1) ) return 7;
    if( n > (6*6-1) ) return 6;
    if( n > (5*5-1) ) return 5;
    if( n > (4*4-1) ) return 4;
    if( n > (3*3-1) ) return 3;
    if( n > (2*2-1) ) return 2;
    if( n > (1*1-1) ) return 1;
    return 0;
}


//初期化
void setup() {

  //I2Cの初期化
  Wire.begin(D9, D10);  //XIAO ESP32C6+SSD1306
  //Wire.begin(D10,D9); //XIAO ESP32C6+GROVE

  // I2Cアドレスは使用するディスプレイに合わせて変更する
  display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS);

}  //setup


//メインループ
void loop() {

  // 画面表示をクリア
  display.fillScreen(BLACK);

  for (int y = 0; y < 30; y++) {

    //(r*r) = (y*y) + (x*x)
    //(30*30) = (y*y) + (x*x)
    //(30*30) - (y*y) = (x*x)
    //x = SQRT(x*x)

    int x, xx;

    xx = (30 * 30) - (y * y);
    x = i_sqrt(xx);

    display.drawPixel(x, y, WHITE);

    delay(50);
    display.display();
  }

  // 描画バッファの内容を画面に表示
  display.display();


  delay(5000);  //5秒待つ

}  //loop



1
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
1
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?