public void main()
{
ServoMotor red = new ServoMotor(CPU.P36);
ServoMotor blue = new ServoMotor(CPU.P05);
ServoMotor green = new ServoMotor(CPU.P37);
red.Start();
blue.Start();
green.Start();
DigitalOut led = new DigitalOut(CPU.P22);
double y = 2 * System.Math.PI / 3.0;
while (true)
{
for (double p = 0.0; p < System.Math.PI * 4.0; p += 0.1)
{
red.DutyCycle = (System.Math.Cos(p) + 1) / 2;
green.DutyCycle = (System.Math.Cos(p + y) + 1) / 2;
blue.DutyCycle = (System.Math.Cos(p + y * 2) + 1) / 2;
CPU.wait(0.1);
}
for (int i = 0; i <= 8; i++)
{
led.Value = !led.Value;
if ((i & 1) != 0) red.DutyCycle =1.0;
else red.DutyCycle = 0.0;
if ((i & 2) != 0) green.DutyCycle =1.0;
else green.DutyCycle = 0.0;
if ((i & 4)!=0) blue.DutyCycle =1.0;
else blue.DutyCycle = 0.0;;
CPU.wait(0.5);
}
}
}
|
1
2
3 Cpu.PWMChannel.PWM_0でも良い
4 Cpu.PWMChannel.PWM_1でも良い
5 Cpu.PWMChannel.PWM_2でも良い
6 PWM信号を出力する
7
8
9 デジタルのLEDも付けてみる
10
11
12
13
14
15 赤成分
16 緑成分
17 青成分
18 0.1秒待つ
19
20
21
22 P22に繋いでいるLEDを反転させる
23 以下純色の点滅
24
25
26
27
28
29 0.5秒待つ
30
31
32
|