![]() |
GHIという会社が開発している教育用ボードです。scratchという子供向けのプログラミングから、C#などの高級言語を学ぶことができます。センサーとして、温度、光量、加速度センサが付いており、また、出力としては直流モータ、サーボモータ、信号機LED、カラーLED、ブザー、LCDディスプレイが付いています。 詳細はこちらを参照してください。 |
プログラム | |
---|---|
void main() { BrainPad.Buzzer.PlayFrequency(440); CPU.delay(100); BrainPad.Buzzer.PlayFrequency(880); CPU.delay(100); BrainPad.Buzzer.Stop(); } |
1 2 3 ブザーを440Hz(ラの音)で鳴らす 4 あるいは、BrainPad.Wait.Milliseconds(100.0); 5 ブザーを880Hz(上のラの音)で鳴らす 6 あるいは、Thread.Sleep(100); 7 ブザーを止める。 8 |
タクトスイッチ | LED | 温度センサ | 光量センサ | LCD | ![]() | ![]() |
![]() | ![]() |
![]() |
---|
プログラム | |
---|---|
void main() { BrainPad.Display.Clear(); BrainPad.Display.DrawString(10, 10, "Brain Pad", BrainPad.Color.Yellow); BrainPad.Display.DrawString(10, 20, "M.Mizuno", BrainPad.Color.Green); BrainPad.TrafficLight.TurnGreenLightOff(); while (BrainPad.Looping) { if (BrainPad.Button.IsDownPressed()) { BrainPad.TrafficLight.TurnGreenLightOn(); } else { BrainPad.TrafficLight.TurnGreenLightOff(); } BrainPad.Wait.Seconds(0.2); int light = (int)(BrainPad.LightSensor.ReadLightLevel() * 1000); BrainPad.Display.DrawString(10, 40, "LightLevel=" + light.ToString(), BrainPad.Color.Cyan); string temp = BrainPad.TemperatureSensor.ReadTemperature().ToString(); BrainPad.Display.DrawString(10, 55, "Temperature=" + temp.Substring(0,5), BrainPad.Color.Cyan); } } |
1 2 3 ディスプレイ消去 4 x=10,y=10の位置から黄色で文字を書く 5 x=10,y=20の位置から緑色で文字を書く 6 信号機の緑LEDを消灯する 7 永久ループ。while(true)と同じ 8 9 下のスイッチが押された場合 10 11 緑LEDを点灯 12 13 14 15 緑LEDを消灯 16 17 0.2秒待つ 18 光量の測定 19 光量の表示 20 温度の測定 21 温度の表示 22 23 |
![]() | サーボモーターは、PWM(パルス幅変調)の信号指令により指定角度位置に移動するデバイスです。下記の図で、1msと書かれている幅(Duty Cycle)が角度情報になります。 |
BrainPad.csのこの部分を探す |
---|
public static void SetPosition(int position) { if (position < 0 || position > 180) throw new ArgumentOutOfRangeException("degrees", "degrees must be between 0 and 180."); Stop(); output.Period = 20000; output.Duration = (uint)(1000.0 + ((position / 180.0) * 1000.0)); Start(); } |
プログラム | |
---|---|
void main() { BrainPad.Display.Clear(); int step = 5; BrainPad.ServoMotor.SetPosition(0); BrainPad.ServoMotor.Start(); while (true) { for (int i = 0; i < 180; i += step) { BrainPad.ServoMotor.SetPosition(i); CPU.delay(30); } for (int i = 180; i > 0; i -= step) { BrainPad.ServoMotor.SetPosition(i); CPU.delay(30); } } } |
1 2 3 関係ないが、ディスプレイを消去 4 5度ずつ移動させる予定 5 サーボモーターの初期位置(移動はしない) 6 サーボモーター動作開始 7 永久ループ 8 9 0度からstep(5度)刻みで180度まで移動する予定 10 11 サーボモーターを移動させる 12 推定移動時間 13 14 逆方向に回転させる 15 16 17 18 19 20 |
プログラム | |
---|---|
private void main() { BrainPad.Display.Clear(); int step = 5; BoeBotLib.ServoMotor sv = new BoeBotLib.ServoMotor(CPU.E9, 1408u, 1458u, 1508u); sv.Start(); while (true) { for (int i = -100; i <= 100; i += step) { sv.move(i); CPU.delay(500); } for (int i = 100; i >= -100; i -= step) { sv.move(i); CPU.delay(500); } } } |
1 2 3 4 5%ずつスピードを変化させる 5 拡張コネクタのE9にサーボモーターを繋げる 6 +方向100%スピードの幅1408μ秒、停止1458μ秒 7 -方向100%スピードの幅1508μ秒で、信号スタート 8 9 -100%のスピードから+100%のスピードで回転予定 10 11 指定のスピードで回転させる 12 13 14 逆シーケンス 15 16 17 18 19 20 |