This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
float distance = sensor.readRangeSingleMillimeters();//TOF距離センサーの値を取得(単位:mm) | |
bool offsetButtonState = digitalRead(ORIGIN_BUTTON); //原点設定ボタンの状態を取得 | |
if ( offsetButtonState == 0 && prevButtonState == 1 )//原点設定ボタンが押されたら、 | |
{ | |
origin = distance;//originを現在のdistanceに変更 | |
} | |
prevButtonState = offsetButtonState;//prevButtonStateを更新 | |
float frequency = map(distance, origin, origin-heightRange, minFreq, maxFreq);//距離を周波数に変換 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SparkFun_TB6612.h> | |
#define AIN1 2 | |
#define AIN2 4 | |
#define PWMA 5 | |
#define STBY 9 | |
const int offsetA = 1; | |
Motor motor1 = Motor(AIN1, AIN2, PWMA, offsetA, STBY); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Wire.h> | |
#include <VL6180X.h> | |
#define SPEAKER 8 | |
VL6180X sensor; | |
void setup() | |
{ | |
Serial.begin(9600); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int VOL_PIN = A0; | |
void setup(){ | |
Serial.begin( 9600 ); | |
} | |
void loop(){ | |
int value; | |
float volt; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int DIN_PIN = 7; | |
void setup(){ | |
pinMode( DIN_PIN, INPUT_PULLUP ); | |
Serial.begin( 9600 ); | |
} | |
void loop(){ | |
int value; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define WIDTH 5//LEDの横の数 | |
#define HEIGHT 5//LEDの縦の数 | |
#define LED_PIN 6//LEDテープの信号線 | |
#define INTERVAL 750//画面切り替えのインターバル | |
#define MAX_BRIGHTNESS 32//動植物の最大の明るさ | |
#define ANIMAL_MAX_NUM 10//動物の最大数 | |
#define ANIMAL_DECREASE 1//動物の体力減少 | |
#define GRASS_GROWTH_NUM 3//同時に草が成長する箇所 | |
#define GRASS_GROWTH_POTENTIAL 2//草が成長するスピード | |
#define KNOCK_THRESHOLD 5000//ノックと判断する閾値 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. #define WIDTH 5//LEDの横の数 | |
2. #define HEIGHT 5//LEDの縦の数 | |
3. #define LED_PIN 6//LEDテープの信号線 | |
4. #define INTERVAL 750//画面切り替えのインターバル | |
5. #define MAX_BRIGHTNESS 32//動植物の最大の明るさ | |
6. #define ANIMAL_MAX_NUM 10//動物の最大数 | |
7. #define ANIMAL_DECREASE 1//動物の体力減少 | |
8. #define GRASS_GROWTH_NUM 3//同時に草が成長する箇所 | |
9. #define GRASS_GROWTH_POTENTIAL 2//草が成長するスピード | |
10. #define KNOCK_THRESHOLD 5000//ノックと判断する閾値 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
//体力が上限になったら増える | |
if ( animals[i].life > MAX_BRIGHTNESS ) | |
{ | |
animals[i].life = MAX_BRIGHTNESS / 2; | |
bornAnimal(i); | |
} | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
// 加速度センサーが反応していれば、動物を増やす | |
if ( bornFlag ) | |
{ | |
bornFlag = false; | |
bornAnimal(-1); | |
} | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
struct Animal | |
{ | |
float x; | |
float y; | |
int life; | |
bool isDead; | |
RGB color; | |
}; |