[No.8]繰り返しの技を使いこなそう!〜ライトを順番に点灯
![](https://s3.ap-northeast-1.amazonaws.com/spaceblock.jp-storage/inquiries/2024-03-26/mmdYzeU5IXsIqNUNU396x.png?AWSAccessKeyId=ASIAZZVIWFLRYPYCASPF&Expires=1725768969&Signature=6Sxcau7VSLBHG2Yn3iR1ZJVsvo0%3D&x-amz-security-token=IQoJb3JpZ2luX2VjEBIaDmFwLW5vcnRoZWFzdC0xIkgwRgIhAMKKk4aPUJn0e3SMDa3%2FAteardhsO4C2QmZ%2FkpDJXcREAiEA5h1%2BhXMSAVKKhjvcAZ3JU%2FoECFek1D9LtUesx0G6ZkcqlAMIOxABGgw2NzM1ODk4OTc5NTUiDLP6gTNK2iBRQ0QEgCrxAre5ARThtFYiP5HewoKJlDsZ%2Fym9MJOratwTQ9mb3bhJubMItXViaFiSPI8BowsTLnGCxorQFqzSDW9PG05Z4D1jSUBH9Mhn0XE3SM%2BH66V86Tnci%2BdakfPPKnmEzbccndH80Z6m4jfOFQKHWXUuWNb0lBa6WFR9MmesdFj88%2FRRBgooF8chJBXQ9uBZgq%2FAuaY%2Bbyly3iIlMWXpgXUQy1tLuD5Sq7HEF8%2FB5ziU40hTprO%2B2jFPcRPNIhJEFNy%2BJpj%2Fq9ftmp2wYSuTwDF30wnZdZsiVW1pxwjadXMPUEecpeKukqEhtKcyl1IOIlojPFJphRJZZ%2BY0vgBgKhD%2BJZiKG3Kx9FSKT9Dz1sYdfWMQElc6yFFOnZ6R5hpdSHVWxLLdEW8d8S85H5xlSb26Q0JiCNupA4u9jENLdP%2BS02ry0q19vEzYrD%2B%2Fmo6gjXXZa6U66dUlVLSmhl0ZV%2FD17G4DrbZyTZIPv8okvFZpqYvvUTCpivS2BjqcATPuLjpWxhuwUWl1HwkKq2WH3PK4sfLQGRY%2Fmc8xZ0IzU6IDaMosEV%2B4LFr33F1IadIBT9rZVJZ2BBeI6vAQnKMWSeEnjHIXZANw8%2Fk0Kw7DNj46HKVTWfWkDGwH5a3MvBjxo18yawLeYwNSfetGVpS6TMMz8BArcKp7OTbcaLeyXC4Qr%2F0Hoevcuipf9syVdc74eLpb6gIDf9r4Qg%3D%3D)
小さなものづくりコンピューター「SPACEBLOCK(スペースブロック)」でさまざまな機能を作るために、プログラミングの技を磨いていきましょう。今回は、LEDパネルを使って、 プログラミングの基本技である「繰り返し」を使いますよ!
必要なもの&準備
- SPACEBLOCK通常パッケージ[SPACEBLOCK本体、USBケーブル、(電池ボックス)]
- 8×8 RGB LEDマトリックスパネル(LEDパネル)
- プログラミングをするパソコン
![](https://s3.ap-northeast-1.amazonaws.com/spaceblock.jp-storage/inquiries/2024-03-26/QWj2V1zwpidPh3HQuoYx4.png?AWSAccessKeyId=ASIAZZVIWFLRYPYCASPF&Expires=1725768969&Signature=qxv5ZE21%2BhzhSfHOjSPRJYTDIGg%3D&x-amz-security-token=IQoJb3JpZ2luX2VjEBIaDmFwLW5vcnRoZWFzdC0xIkgwRgIhAMKKk4aPUJn0e3SMDa3%2FAteardhsO4C2QmZ%2FkpDJXcREAiEA5h1%2BhXMSAVKKhjvcAZ3JU%2FoECFek1D9LtUesx0G6ZkcqlAMIOxABGgw2NzM1ODk4OTc5NTUiDLP6gTNK2iBRQ0QEgCrxAre5ARThtFYiP5HewoKJlDsZ%2Fym9MJOratwTQ9mb3bhJubMItXViaFiSPI8BowsTLnGCxorQFqzSDW9PG05Z4D1jSUBH9Mhn0XE3SM%2BH66V86Tnci%2BdakfPPKnmEzbccndH80Z6m4jfOFQKHWXUuWNb0lBa6WFR9MmesdFj88%2FRRBgooF8chJBXQ9uBZgq%2FAuaY%2Bbyly3iIlMWXpgXUQy1tLuD5Sq7HEF8%2FB5ziU40hTprO%2B2jFPcRPNIhJEFNy%2BJpj%2Fq9ftmp2wYSuTwDF30wnZdZsiVW1pxwjadXMPUEecpeKukqEhtKcyl1IOIlojPFJphRJZZ%2BY0vgBgKhD%2BJZiKG3Kx9FSKT9Dz1sYdfWMQElc6yFFOnZ6R5hpdSHVWxLLdEW8d8S85H5xlSb26Q0JiCNupA4u9jENLdP%2BS02ry0q19vEzYrD%2B%2Fmo6gjXXZa6U66dUlVLSmhl0ZV%2FD17G4DrbZyTZIPv8okvFZpqYvvUTCpivS2BjqcATPuLjpWxhuwUWl1HwkKq2WH3PK4sfLQGRY%2Fmc8xZ0IzU6IDaMosEV%2B4LFr33F1IadIBT9rZVJZ2BBeI6vAQnKMWSeEnjHIXZANw8%2Fk0Kw7DNj46HKVTWfWkDGwH5a3MvBjxo18yawLeYwNSfetGVpS6TMMz8BArcKp7OTbcaLeyXC4Qr%2F0Hoevcuipf9syVdc74eLpb6gIDf9r4Qg%3D%3D)
SPACEBLOCKにLEDパネルを接続する
![](https://s3.ap-northeast-1.amazonaws.com/spaceblock.jp-storage/inquiries/2024-03-26/W3Kw8KVQOzHkWLXRwE7Vk.png?AWSAccessKeyId=ASIAZZVIWFLRYPYCASPF&Expires=1725768969&Signature=7E9dcECX7HnWzpVQ5kf0xRoixEA%3D&x-amz-security-token=IQoJb3JpZ2luX2VjEBIaDmFwLW5vcnRoZWFzdC0xIkgwRgIhAMKKk4aPUJn0e3SMDa3%2FAteardhsO4C2QmZ%2FkpDJXcREAiEA5h1%2BhXMSAVKKhjvcAZ3JU%2FoECFek1D9LtUesx0G6ZkcqlAMIOxABGgw2NzM1ODk4OTc5NTUiDLP6gTNK2iBRQ0QEgCrxAre5ARThtFYiP5HewoKJlDsZ%2Fym9MJOratwTQ9mb3bhJubMItXViaFiSPI8BowsTLnGCxorQFqzSDW9PG05Z4D1jSUBH9Mhn0XE3SM%2BH66V86Tnci%2BdakfPPKnmEzbccndH80Z6m4jfOFQKHWXUuWNb0lBa6WFR9MmesdFj88%2FRRBgooF8chJBXQ9uBZgq%2FAuaY%2Bbyly3iIlMWXpgXUQy1tLuD5Sq7HEF8%2FB5ziU40hTprO%2B2jFPcRPNIhJEFNy%2BJpj%2Fq9ftmp2wYSuTwDF30wnZdZsiVW1pxwjadXMPUEecpeKukqEhtKcyl1IOIlojPFJphRJZZ%2BY0vgBgKhD%2BJZiKG3Kx9FSKT9Dz1sYdfWMQElc6yFFOnZ6R5hpdSHVWxLLdEW8d8S85H5xlSb26Q0JiCNupA4u9jENLdP%2BS02ry0q19vEzYrD%2B%2Fmo6gjXXZa6U66dUlVLSmhl0ZV%2FD17G4DrbZyTZIPv8okvFZpqYvvUTCpivS2BjqcATPuLjpWxhuwUWl1HwkKq2WH3PK4sfLQGRY%2Fmc8xZ0IzU6IDaMosEV%2B4LFr33F1IadIBT9rZVJZ2BBeI6vAQnKMWSeEnjHIXZANw8%2Fk0Kw7DNj46HKVTWfWkDGwH5a3MvBjxo18yawLeYwNSfetGVpS6TMMz8BArcKp7OTbcaLeyXC4Qr%2F0Hoevcuipf9syVdc74eLpb6gIDf9r4Qg%3D%3D)
ジャンパーワイヤを接続する場合、細かい部分は以下の図を参考にしてください。
![](https://s3.ap-northeast-1.amazonaws.com/spaceblock.jp-storage/inquiries/2024-03-26/igVfaCPi3S76-skjMNUNw.png?AWSAccessKeyId=ASIAZZVIWFLRYPYCASPF&Expires=1725768969&Signature=qzDPzax2%2FqeKH%2BEI1H9O1n3ziGA%3D&x-amz-security-token=IQoJb3JpZ2luX2VjEBIaDmFwLW5vcnRoZWFzdC0xIkgwRgIhAMKKk4aPUJn0e3SMDa3%2FAteardhsO4C2QmZ%2FkpDJXcREAiEA5h1%2BhXMSAVKKhjvcAZ3JU%2FoECFek1D9LtUesx0G6ZkcqlAMIOxABGgw2NzM1ODk4OTc5NTUiDLP6gTNK2iBRQ0QEgCrxAre5ARThtFYiP5HewoKJlDsZ%2Fym9MJOratwTQ9mb3bhJubMItXViaFiSPI8BowsTLnGCxorQFqzSDW9PG05Z4D1jSUBH9Mhn0XE3SM%2BH66V86Tnci%2BdakfPPKnmEzbccndH80Z6m4jfOFQKHWXUuWNb0lBa6WFR9MmesdFj88%2FRRBgooF8chJBXQ9uBZgq%2FAuaY%2Bbyly3iIlMWXpgXUQy1tLuD5Sq7HEF8%2FB5ziU40hTprO%2B2jFPcRPNIhJEFNy%2BJpj%2Fq9ftmp2wYSuTwDF30wnZdZsiVW1pxwjadXMPUEecpeKukqEhtKcyl1IOIlojPFJphRJZZ%2BY0vgBgKhD%2BJZiKG3Kx9FSKT9Dz1sYdfWMQElc6yFFOnZ6R5hpdSHVWxLLdEW8d8S85H5xlSb26Q0JiCNupA4u9jENLdP%2BS02ry0q19vEzYrD%2B%2Fmo6gjXXZa6U66dUlVLSmhl0ZV%2FD17G4DrbZyTZIPv8okvFZpqYvvUTCpivS2BjqcATPuLjpWxhuwUWl1HwkKq2WH3PK4sfLQGRY%2Fmc8xZ0IzU6IDaMosEV%2B4LFr33F1IadIBT9rZVJZ2BBeI6vAQnKMWSeEnjHIXZANw8%2Fk0Kw7DNj46HKVTWfWkDGwH5a3MvBjxo18yawLeYwNSfetGVpS6TMMz8BArcKp7OTbcaLeyXC4Qr%2F0Hoevcuipf9syVdc74eLpb6gIDf9r4Qg%3D%3D)
要注意マークを表示する
![](https://s3.ap-northeast-1.amazonaws.com/spaceblock.jp-storage/inquiries/2024-03-26/bhZENsiZ8r2yMshbAT2Ga.png?AWSAccessKeyId=ASIAZZVIWFLRYPYCASPF&Expires=1725768969&Signature=nZS0x%2BRV7EnGGYgpJPTHV98irmU%3D&x-amz-security-token=IQoJb3JpZ2luX2VjEBIaDmFwLW5vcnRoZWFzdC0xIkgwRgIhAMKKk4aPUJn0e3SMDa3%2FAteardhsO4C2QmZ%2FkpDJXcREAiEA5h1%2BhXMSAVKKhjvcAZ3JU%2FoECFek1D9LtUesx0G6ZkcqlAMIOxABGgw2NzM1ODk4OTc5NTUiDLP6gTNK2iBRQ0QEgCrxAre5ARThtFYiP5HewoKJlDsZ%2Fym9MJOratwTQ9mb3bhJubMItXViaFiSPI8BowsTLnGCxorQFqzSDW9PG05Z4D1jSUBH9Mhn0XE3SM%2BH66V86Tnci%2BdakfPPKnmEzbccndH80Z6m4jfOFQKHWXUuWNb0lBa6WFR9MmesdFj88%2FRRBgooF8chJBXQ9uBZgq%2FAuaY%2Bbyly3iIlMWXpgXUQy1tLuD5Sq7HEF8%2FB5ziU40hTprO%2B2jFPcRPNIhJEFNy%2BJpj%2Fq9ftmp2wYSuTwDF30wnZdZsiVW1pxwjadXMPUEecpeKukqEhtKcyl1IOIlojPFJphRJZZ%2BY0vgBgKhD%2BJZiKG3Kx9FSKT9Dz1sYdfWMQElc6yFFOnZ6R5hpdSHVWxLLdEW8d8S85H5xlSb26Q0JiCNupA4u9jENLdP%2BS02ry0q19vEzYrD%2B%2Fmo6gjXXZa6U66dUlVLSmhl0ZV%2FD17G4DrbZyTZIPv8okvFZpqYvvUTCpivS2BjqcATPuLjpWxhuwUWl1HwkKq2WH3PK4sfLQGRY%2Fmc8xZ0IzU6IDaMosEV%2B4LFr33F1IadIBT9rZVJZ2BBeI6vAQnKMWSeEnjHIXZANw8%2Fk0Kw7DNj46HKVTWfWkDGwH5a3MvBjxo18yawLeYwNSfetGVpS6TMMz8BArcKp7OTbcaLeyXC4Qr%2F0Hoevcuipf9syVdc74eLpb6gIDf9r4Qg%3D%3D)
「!」マークが点灯し、1秒経つと消えるプログラムができました。もっと目立たせたいので、このマークを点滅させてみましょう。
マークを点滅させるには?
点滅というのは、「点灯→消灯→点灯→消灯→点灯→消灯→点灯→消灯→点灯→消灯→点灯→消灯→点灯→消灯→」……という状態です。「点灯→消灯→」というパターンを何度も繰り返していますね。
同じパターンの命令を繰り返すのに使うのが、「繰り返し」カテゴリーの[繰り返す]ブロックです。[繰り返す]ブロックは、間にはさんだ命令ブロックをずっと繰り返して実行します。
![](https://s3.ap-northeast-1.amazonaws.com/spaceblock.jp-storage/inquiries/2024-03-26/aofVy6dphbdtDYu3N41eX.png?AWSAccessKeyId=ASIAZZVIWFLRYPYCASPF&Expires=1725768969&Signature=F1QFle1TLYeWKgYohJwt%2FJz86tE%3D&x-amz-security-token=IQoJb3JpZ2luX2VjEBIaDmFwLW5vcnRoZWFzdC0xIkgwRgIhAMKKk4aPUJn0e3SMDa3%2FAteardhsO4C2QmZ%2FkpDJXcREAiEA5h1%2BhXMSAVKKhjvcAZ3JU%2FoECFek1D9LtUesx0G6ZkcqlAMIOxABGgw2NzM1ODk4OTc5NTUiDLP6gTNK2iBRQ0QEgCrxAre5ARThtFYiP5HewoKJlDsZ%2Fym9MJOratwTQ9mb3bhJubMItXViaFiSPI8BowsTLnGCxorQFqzSDW9PG05Z4D1jSUBH9Mhn0XE3SM%2BH66V86Tnci%2BdakfPPKnmEzbccndH80Z6m4jfOFQKHWXUuWNb0lBa6WFR9MmesdFj88%2FRRBgooF8chJBXQ9uBZgq%2FAuaY%2Bbyly3iIlMWXpgXUQy1tLuD5Sq7HEF8%2FB5ziU40hTprO%2B2jFPcRPNIhJEFNy%2BJpj%2Fq9ftmp2wYSuTwDF30wnZdZsiVW1pxwjadXMPUEecpeKukqEhtKcyl1IOIlojPFJphRJZZ%2BY0vgBgKhD%2BJZiKG3Kx9FSKT9Dz1sYdfWMQElc6yFFOnZ6R5hpdSHVWxLLdEW8d8S85H5xlSb26Q0JiCNupA4u9jENLdP%2BS02ry0q19vEzYrD%2B%2Fmo6gjXXZa6U66dUlVLSmhl0ZV%2FD17G4DrbZyTZIPv8okvFZpqYvvUTCpivS2BjqcATPuLjpWxhuwUWl1HwkKq2WH3PK4sfLQGRY%2Fmc8xZ0IzU6IDaMosEV%2B4LFr33F1IadIBT9rZVJZ2BBeI6vAQnKMWSeEnjHIXZANw8%2Fk0Kw7DNj46HKVTWfWkDGwH5a3MvBjxo18yawLeYwNSfetGVpS6TMMz8BArcKp7OTbcaLeyXC4Qr%2F0Hoevcuipf9syVdc74eLpb6gIDf9r4Qg%3D%3D)
[プログラム開始]に[繰り返す]ブロックをつなぎ、その内側に次の図の通りプログラムを作成しましょう。
![](https://s3.ap-northeast-1.amazonaws.com/spaceblock.jp-storage/inquiries/2024-03-26/QHLQNvsRA5V3if0ynCxbX.png?AWSAccessKeyId=ASIAZZVIWFLRYPYCASPF&Expires=1725768969&Signature=8IOgIOkjhxiQook2YiX0Wmar0t8%3D&x-amz-security-token=IQoJb3JpZ2luX2VjEBIaDmFwLW5vcnRoZWFzdC0xIkgwRgIhAMKKk4aPUJn0e3SMDa3%2FAteardhsO4C2QmZ%2FkpDJXcREAiEA5h1%2BhXMSAVKKhjvcAZ3JU%2FoECFek1D9LtUesx0G6ZkcqlAMIOxABGgw2NzM1ODk4OTc5NTUiDLP6gTNK2iBRQ0QEgCrxAre5ARThtFYiP5HewoKJlDsZ%2Fym9MJOratwTQ9mb3bhJubMItXViaFiSPI8BowsTLnGCxorQFqzSDW9PG05Z4D1jSUBH9Mhn0XE3SM%2BH66V86Tnci%2BdakfPPKnmEzbccndH80Z6m4jfOFQKHWXUuWNb0lBa6WFR9MmesdFj88%2FRRBgooF8chJBXQ9uBZgq%2FAuaY%2Bbyly3iIlMWXpgXUQy1tLuD5Sq7HEF8%2FB5ziU40hTprO%2B2jFPcRPNIhJEFNy%2BJpj%2Fq9ftmp2wYSuTwDF30wnZdZsiVW1pxwjadXMPUEecpeKukqEhtKcyl1IOIlojPFJphRJZZ%2BY0vgBgKhD%2BJZiKG3Kx9FSKT9Dz1sYdfWMQElc6yFFOnZ6R5hpdSHVWxLLdEW8d8S85H5xlSb26Q0JiCNupA4u9jENLdP%2BS02ry0q19vEzYrD%2B%2Fmo6gjXXZa6U66dUlVLSmhl0ZV%2FD17G4DrbZyTZIPv8okvFZpqYvvUTCpivS2BjqcATPuLjpWxhuwUWl1HwkKq2WH3PK4sfLQGRY%2Fmc8xZ0IzU6IDaMosEV%2B4LFr33F1IadIBT9rZVJZ2BBeI6vAQnKMWSeEnjHIXZANw8%2Fk0Kw7DNj46HKVTWfWkDGwH5a3MvBjxo18yawLeYwNSfetGVpS6TMMz8BArcKp7OTbcaLeyXC4Qr%2F0Hoevcuipf9syVdc74eLpb6gIDf9r4Qg%3D%3D)
動画で見てみましょう。
LEDを1個ずつ順番に点灯させるには?
次に、LEDパネルのライトを1個ずつ順番に点灯させてみましょう。LEDパネルには8×8の合計64個のLEDが並んでいて、これら1個ずつを個別に指定して点灯したり消灯したりすることができます。
ライトの位置を指定して点灯するには、「LED」カテゴリーの[8×8 RGB LED《A10》のx《1》y《1》を《色》に点灯]というブロックを使います。位置は、x座標、y座標で指定します。
![](https://s3.ap-northeast-1.amazonaws.com/spaceblock.jp-storage/inquiries/2024-03-26/KHJtn5giv5YGbMCqBzlcC.png?AWSAccessKeyId=ASIAZZVIWFLRYPYCASPF&Expires=1725768969&Signature=qbL4VRJyRt1YFgzCP7Qxf4Jyf20%3D&x-amz-security-token=IQoJb3JpZ2luX2VjEBIaDmFwLW5vcnRoZWFzdC0xIkgwRgIhAMKKk4aPUJn0e3SMDa3%2FAteardhsO4C2QmZ%2FkpDJXcREAiEA5h1%2BhXMSAVKKhjvcAZ3JU%2FoECFek1D9LtUesx0G6ZkcqlAMIOxABGgw2NzM1ODk4OTc5NTUiDLP6gTNK2iBRQ0QEgCrxAre5ARThtFYiP5HewoKJlDsZ%2Fym9MJOratwTQ9mb3bhJubMItXViaFiSPI8BowsTLnGCxorQFqzSDW9PG05Z4D1jSUBH9Mhn0XE3SM%2BH66V86Tnci%2BdakfPPKnmEzbccndH80Z6m4jfOFQKHWXUuWNb0lBa6WFR9MmesdFj88%2FRRBgooF8chJBXQ9uBZgq%2FAuaY%2Bbyly3iIlMWXpgXUQy1tLuD5Sq7HEF8%2FB5ziU40hTprO%2B2jFPcRPNIhJEFNy%2BJpj%2Fq9ftmp2wYSuTwDF30wnZdZsiVW1pxwjadXMPUEecpeKukqEhtKcyl1IOIlojPFJphRJZZ%2BY0vgBgKhD%2BJZiKG3Kx9FSKT9Dz1sYdfWMQElc6yFFOnZ6R5hpdSHVWxLLdEW8d8S85H5xlSb26Q0JiCNupA4u9jENLdP%2BS02ry0q19vEzYrD%2B%2Fmo6gjXXZa6U66dUlVLSmhl0ZV%2FD17G4DrbZyTZIPv8okvFZpqYvvUTCpivS2BjqcATPuLjpWxhuwUWl1HwkKq2WH3PK4sfLQGRY%2Fmc8xZ0IzU6IDaMosEV%2B4LFr33F1IadIBT9rZVJZ2BBeI6vAQnKMWSeEnjHIXZANw8%2Fk0Kw7DNj46HKVTWfWkDGwH5a3MvBjxo18yawLeYwNSfetGVpS6TMMz8BArcKp7OTbcaLeyXC4Qr%2F0Hoevcuipf9syVdc74eLpb6gIDf9r4Qg%3D%3D)
横方向 8個のLEDを順番に点灯させる
![](https://s3.ap-northeast-1.amazonaws.com/spaceblock.jp-storage/inquiries/2024-03-26/O-6AwfyTXkj9B_nd_afaq.png?AWSAccessKeyId=ASIAZZVIWFLRYPYCASPF&Expires=1725768969&Signature=Q3uMASbndQSQXChCtzAd9FwMLz4%3D&x-amz-security-token=IQoJb3JpZ2luX2VjEBIaDmFwLW5vcnRoZWFzdC0xIkgwRgIhAMKKk4aPUJn0e3SMDa3%2FAteardhsO4C2QmZ%2FkpDJXcREAiEA5h1%2BhXMSAVKKhjvcAZ3JU%2FoECFek1D9LtUesx0G6ZkcqlAMIOxABGgw2NzM1ODk4OTc5NTUiDLP6gTNK2iBRQ0QEgCrxAre5ARThtFYiP5HewoKJlDsZ%2Fym9MJOratwTQ9mb3bhJubMItXViaFiSPI8BowsTLnGCxorQFqzSDW9PG05Z4D1jSUBH9Mhn0XE3SM%2BH66V86Tnci%2BdakfPPKnmEzbccndH80Z6m4jfOFQKHWXUuWNb0lBa6WFR9MmesdFj88%2FRRBgooF8chJBXQ9uBZgq%2FAuaY%2Bbyly3iIlMWXpgXUQy1tLuD5Sq7HEF8%2FB5ziU40hTprO%2B2jFPcRPNIhJEFNy%2BJpj%2Fq9ftmp2wYSuTwDF30wnZdZsiVW1pxwjadXMPUEecpeKukqEhtKcyl1IOIlojPFJphRJZZ%2BY0vgBgKhD%2BJZiKG3Kx9FSKT9Dz1sYdfWMQElc6yFFOnZ6R5hpdSHVWxLLdEW8d8S85H5xlSb26Q0JiCNupA4u9jENLdP%2BS02ry0q19vEzYrD%2B%2Fmo6gjXXZa6U66dUlVLSmhl0ZV%2FD17G4DrbZyTZIPv8okvFZpqYvvUTCpivS2BjqcATPuLjpWxhuwUWl1HwkKq2WH3PK4sfLQGRY%2Fmc8xZ0IzU6IDaMosEV%2B4LFr33F1IadIBT9rZVJZ2BBeI6vAQnKMWSeEnjHIXZANw8%2Fk0Kw7DNj46HKVTWfWkDGwH5a3MvBjxo18yawLeYwNSfetGVpS6TMMz8BArcKp7OTbcaLeyXC4Qr%2F0Hoevcuipf9syVdc74eLpb6gIDf9r4Qg%3D%3D)
このように、命令ブロックをどんどんつないでも良いのですが、数が増えるとプログラムを作るのがとても大変です。
プログラムを点検すると、同じブロックが繰り返しつながっていて、[8×8 RGB LED《A10》のx《1》y《1》を《色》に点灯]ブロックのx座標の値だけが違います。x座標の値は、順番に1から8まで1ずつ増えていますね。このように、ある値が規則的に変化しながら繰り返しをしている場合、「変数(へんすう)」を使うと効率よくプログラムを作ることができます。
「変数」と繰り返しで効率アップ!
「変数(へんすう)」は、値を入れておくことができる入れ物で、自分で好きな名前をつけられます。変数に入れておく値は、プログラムの途中で入れ替えることができます。
まず、次の図の手順通り新しい変数を作りましょう、名前は「X」とします。
![](https://s3.ap-northeast-1.amazonaws.com/spaceblock.jp-storage/inquiries/2024-03-26/-2udtWGJUZ3W8An7ANhHl.png?AWSAccessKeyId=ASIAZZVIWFLRYPYCASPF&Expires=1725768969&Signature=49UfVb9zSZNqDhNQb0HHesAblHg%3D&x-amz-security-token=IQoJb3JpZ2luX2VjEBIaDmFwLW5vcnRoZWFzdC0xIkgwRgIhAMKKk4aPUJn0e3SMDa3%2FAteardhsO4C2QmZ%2FkpDJXcREAiEA5h1%2BhXMSAVKKhjvcAZ3JU%2FoECFek1D9LtUesx0G6ZkcqlAMIOxABGgw2NzM1ODk4OTc5NTUiDLP6gTNK2iBRQ0QEgCrxAre5ARThtFYiP5HewoKJlDsZ%2Fym9MJOratwTQ9mb3bhJubMItXViaFiSPI8BowsTLnGCxorQFqzSDW9PG05Z4D1jSUBH9Mhn0XE3SM%2BH66V86Tnci%2BdakfPPKnmEzbccndH80Z6m4jfOFQKHWXUuWNb0lBa6WFR9MmesdFj88%2FRRBgooF8chJBXQ9uBZgq%2FAuaY%2Bbyly3iIlMWXpgXUQy1tLuD5Sq7HEF8%2FB5ziU40hTprO%2B2jFPcRPNIhJEFNy%2BJpj%2Fq9ftmp2wYSuTwDF30wnZdZsiVW1pxwjadXMPUEecpeKukqEhtKcyl1IOIlojPFJphRJZZ%2BY0vgBgKhD%2BJZiKG3Kx9FSKT9Dz1sYdfWMQElc6yFFOnZ6R5hpdSHVWxLLdEW8d8S85H5xlSb26Q0JiCNupA4u9jENLdP%2BS02ry0q19vEzYrD%2B%2Fmo6gjXXZa6U66dUlVLSmhl0ZV%2FD17G4DrbZyTZIPv8okvFZpqYvvUTCpivS2BjqcATPuLjpWxhuwUWl1HwkKq2WH3PK4sfLQGRY%2Fmc8xZ0IzU6IDaMosEV%2B4LFr33F1IadIBT9rZVJZ2BBeI6vAQnKMWSeEnjHIXZANw8%2Fk0Kw7DNj46HKVTWfWkDGwH5a3MvBjxo18yawLeYwNSfetGVpS6TMMz8BArcKp7OTbcaLeyXC4Qr%2F0Hoevcuipf9syVdc74eLpb6gIDf9r4Qg%3D%3D)
次に、今作った変数「X」に、最初の値として「1」を入れます。次の図の通り、[プログラム開始]ブロックに[数字《X》に《 》をセット]をつなぎ、1を指定してください。
![](https://s3.ap-northeast-1.amazonaws.com/spaceblock.jp-storage/inquiries/2024-03-26/gQW6nj51xMXJpGKB22AgA.png?AWSAccessKeyId=ASIAZZVIWFLRYPYCASPF&Expires=1725768969&Signature=S8yBsPAflkYCHHmiFFEqeH%2FmLos%3D&x-amz-security-token=IQoJb3JpZ2luX2VjEBIaDmFwLW5vcnRoZWFzdC0xIkgwRgIhAMKKk4aPUJn0e3SMDa3%2FAteardhsO4C2QmZ%2FkpDJXcREAiEA5h1%2BhXMSAVKKhjvcAZ3JU%2FoECFek1D9LtUesx0G6ZkcqlAMIOxABGgw2NzM1ODk4OTc5NTUiDLP6gTNK2iBRQ0QEgCrxAre5ARThtFYiP5HewoKJlDsZ%2Fym9MJOratwTQ9mb3bhJubMItXViaFiSPI8BowsTLnGCxorQFqzSDW9PG05Z4D1jSUBH9Mhn0XE3SM%2BH66V86Tnci%2BdakfPPKnmEzbccndH80Z6m4jfOFQKHWXUuWNb0lBa6WFR9MmesdFj88%2FRRBgooF8chJBXQ9uBZgq%2FAuaY%2Bbyly3iIlMWXpgXUQy1tLuD5Sq7HEF8%2FB5ziU40hTprO%2B2jFPcRPNIhJEFNy%2BJpj%2Fq9ftmp2wYSuTwDF30wnZdZsiVW1pxwjadXMPUEecpeKukqEhtKcyl1IOIlojPFJphRJZZ%2BY0vgBgKhD%2BJZiKG3Kx9FSKT9Dz1sYdfWMQElc6yFFOnZ6R5hpdSHVWxLLdEW8d8S85H5xlSb26Q0JiCNupA4u9jENLdP%2BS02ry0q19vEzYrD%2B%2Fmo6gjXXZa6U66dUlVLSmhl0ZV%2FD17G4DrbZyTZIPv8okvFZpqYvvUTCpivS2BjqcATPuLjpWxhuwUWl1HwkKq2WH3PK4sfLQGRY%2Fmc8xZ0IzU6IDaMosEV%2B4LFr33F1IadIBT9rZVJZ2BBeI6vAQnKMWSeEnjHIXZANw8%2Fk0Kw7DNj46HKVTWfWkDGwH5a3MvBjxo18yawLeYwNSfetGVpS6TMMz8BArcKp7OTbcaLeyXC4Qr%2F0Hoevcuipf9syVdc74eLpb6gIDf9r4Qg%3D%3D)
続けて、繰り返しを使って、LEDパネルの一番上の行だけ左から順にLEDを点灯させるプログラムを作成します。次の図の通り、[《8》回繰り返す]ブロックの内側にプログラムを作成してください。
![](https://s3.ap-northeast-1.amazonaws.com/spaceblock.jp-storage/inquiries/2024-03-26/kFt-4YvTM9c4Ir_kSDAOk.png?AWSAccessKeyId=ASIAZZVIWFLRYPYCASPF&Expires=1725768969&Signature=Duc8KXKybef5fac%2FHoNe%2F3qtEUQ%3D&x-amz-security-token=IQoJb3JpZ2luX2VjEBIaDmFwLW5vcnRoZWFzdC0xIkgwRgIhAMKKk4aPUJn0e3SMDa3%2FAteardhsO4C2QmZ%2FkpDJXcREAiEA5h1%2BhXMSAVKKhjvcAZ3JU%2FoECFek1D9LtUesx0G6ZkcqlAMIOxABGgw2NzM1ODk4OTc5NTUiDLP6gTNK2iBRQ0QEgCrxAre5ARThtFYiP5HewoKJlDsZ%2Fym9MJOratwTQ9mb3bhJubMItXViaFiSPI8BowsTLnGCxorQFqzSDW9PG05Z4D1jSUBH9Mhn0XE3SM%2BH66V86Tnci%2BdakfPPKnmEzbccndH80Z6m4jfOFQKHWXUuWNb0lBa6WFR9MmesdFj88%2FRRBgooF8chJBXQ9uBZgq%2FAuaY%2Bbyly3iIlMWXpgXUQy1tLuD5Sq7HEF8%2FB5ziU40hTprO%2B2jFPcRPNIhJEFNy%2BJpj%2Fq9ftmp2wYSuTwDF30wnZdZsiVW1pxwjadXMPUEecpeKukqEhtKcyl1IOIlojPFJphRJZZ%2BY0vgBgKhD%2BJZiKG3Kx9FSKT9Dz1sYdfWMQElc6yFFOnZ6R5hpdSHVWxLLdEW8d8S85H5xlSb26Q0JiCNupA4u9jENLdP%2BS02ry0q19vEzYrD%2B%2Fmo6gjXXZa6U66dUlVLSmhl0ZV%2FD17G4DrbZyTZIPv8okvFZpqYvvUTCpivS2BjqcATPuLjpWxhuwUWl1HwkKq2WH3PK4sfLQGRY%2Fmc8xZ0IzU6IDaMosEV%2B4LFr33F1IadIBT9rZVJZ2BBeI6vAQnKMWSeEnjHIXZANw8%2Fk0Kw7DNj46HKVTWfWkDGwH5a3MvBjxo18yawLeYwNSfetGVpS6TMMz8BArcKp7OTbcaLeyXC4Qr%2F0Hoevcuipf9syVdc74eLpb6gIDf9r4Qg%3D%3D)
<プログラムの説明>
❶[8×8 RGB LED《A10》のx《1》y《1》を《色》に点灯]ブロックのx座標の値を変数「X」にします。プログラム実行時に変数「X」に入っている値がx座標になります。
❷変数「X」に、変数「X」に1を足した値を入れます。繰り返すたびに変数「X」に入る値が1ずつ増えます。
変数「X」に入れる値が変化する仕組みを次の図でイメージしてください。
![](https://s3.ap-northeast-1.amazonaws.com/spaceblock.jp-storage/inquiries/2024-03-26/0lBgNB4wpqXBdYbOjyfHr.png?AWSAccessKeyId=ASIAZZVIWFLRYPYCASPF&Expires=1725768969&Signature=XSjV2d%2FLd9VetHYGjHH%2Fqpy3s4U%3D&x-amz-security-token=IQoJb3JpZ2luX2VjEBIaDmFwLW5vcnRoZWFzdC0xIkgwRgIhAMKKk4aPUJn0e3SMDa3%2FAteardhsO4C2QmZ%2FkpDJXcREAiEA5h1%2BhXMSAVKKhjvcAZ3JU%2FoECFek1D9LtUesx0G6ZkcqlAMIOxABGgw2NzM1ODk4OTc5NTUiDLP6gTNK2iBRQ0QEgCrxAre5ARThtFYiP5HewoKJlDsZ%2Fym9MJOratwTQ9mb3bhJubMItXViaFiSPI8BowsTLnGCxorQFqzSDW9PG05Z4D1jSUBH9Mhn0XE3SM%2BH66V86Tnci%2BdakfPPKnmEzbccndH80Z6m4jfOFQKHWXUuWNb0lBa6WFR9MmesdFj88%2FRRBgooF8chJBXQ9uBZgq%2FAuaY%2Bbyly3iIlMWXpgXUQy1tLuD5Sq7HEF8%2FB5ziU40hTprO%2B2jFPcRPNIhJEFNy%2BJpj%2Fq9ftmp2wYSuTwDF30wnZdZsiVW1pxwjadXMPUEecpeKukqEhtKcyl1IOIlojPFJphRJZZ%2BY0vgBgKhD%2BJZiKG3Kx9FSKT9Dz1sYdfWMQElc6yFFOnZ6R5hpdSHVWxLLdEW8d8S85H5xlSb26Q0JiCNupA4u9jENLdP%2BS02ry0q19vEzYrD%2B%2Fmo6gjXXZa6U66dUlVLSmhl0ZV%2FD17G4DrbZyTZIPv8okvFZpqYvvUTCpivS2BjqcATPuLjpWxhuwUWl1HwkKq2WH3PK4sfLQGRY%2Fmc8xZ0IzU6IDaMosEV%2B4LFr33F1IadIBT9rZVJZ2BBeI6vAQnKMWSeEnjHIXZANw8%2Fk0Kw7DNj46HKVTWfWkDGwH5a3MvBjxo18yawLeYwNSfetGVpS6TMMz8BArcKp7OTbcaLeyXC4Qr%2F0Hoevcuipf9syVdc74eLpb6gIDf9r4Qg%3D%3D)
プログラムを実行すると、1行目の左から順にLEDが8個点灯します。
![](https://s3.ap-northeast-1.amazonaws.com/spaceblock.jp-storage/inquiries/2024-03-26/JH5sCQGkxhcmRPjJN5DCs.png?AWSAccessKeyId=ASIAZZVIWFLRYPYCASPF&Expires=1725768969&Signature=fH%2F0uEIjf7DYNGSDqJaV7ydA3wM%3D&x-amz-security-token=IQoJb3JpZ2luX2VjEBIaDmFwLW5vcnRoZWFzdC0xIkgwRgIhAMKKk4aPUJn0e3SMDa3%2FAteardhsO4C2QmZ%2FkpDJXcREAiEA5h1%2BhXMSAVKKhjvcAZ3JU%2FoECFek1D9LtUesx0G6ZkcqlAMIOxABGgw2NzM1ODk4OTc5NTUiDLP6gTNK2iBRQ0QEgCrxAre5ARThtFYiP5HewoKJlDsZ%2Fym9MJOratwTQ9mb3bhJubMItXViaFiSPI8BowsTLnGCxorQFqzSDW9PG05Z4D1jSUBH9Mhn0XE3SM%2BH66V86Tnci%2BdakfPPKnmEzbccndH80Z6m4jfOFQKHWXUuWNb0lBa6WFR9MmesdFj88%2FRRBgooF8chJBXQ9uBZgq%2FAuaY%2Bbyly3iIlMWXpgXUQy1tLuD5Sq7HEF8%2FB5ziU40hTprO%2B2jFPcRPNIhJEFNy%2BJpj%2Fq9ftmp2wYSuTwDF30wnZdZsiVW1pxwjadXMPUEecpeKukqEhtKcyl1IOIlojPFJphRJZZ%2BY0vgBgKhD%2BJZiKG3Kx9FSKT9Dz1sYdfWMQElc6yFFOnZ6R5hpdSHVWxLLdEW8d8S85H5xlSb26Q0JiCNupA4u9jENLdP%2BS02ry0q19vEzYrD%2B%2Fmo6gjXXZa6U66dUlVLSmhl0ZV%2FD17G4DrbZyTZIPv8okvFZpqYvvUTCpivS2BjqcATPuLjpWxhuwUWl1HwkKq2WH3PK4sfLQGRY%2Fmc8xZ0IzU6IDaMosEV%2B4LFr33F1IadIBT9rZVJZ2BBeI6vAQnKMWSeEnjHIXZANw8%2Fk0Kw7DNj46HKVTWfWkDGwH5a3MvBjxo18yawLeYwNSfetGVpS6TMMz8BArcKp7OTbcaLeyXC4Qr%2F0Hoevcuipf9syVdc74eLpb6gIDf9r4Qg%3D%3D)
動画でご覧ください。
全てのLEDを順番に点灯する
![](https://s3.ap-northeast-1.amazonaws.com/spaceblock.jp-storage/inquiries/2024-03-26/RCEHsytPS6xcN8H47VUvv.png?AWSAccessKeyId=ASIAZZVIWFLRYPYCASPF&Expires=1725768969&Signature=7s%2FSbKUr%2BQJHlefmaP0rkz2Tc14%3D&x-amz-security-token=IQoJb3JpZ2luX2VjEBIaDmFwLW5vcnRoZWFzdC0xIkgwRgIhAMKKk4aPUJn0e3SMDa3%2FAteardhsO4C2QmZ%2FkpDJXcREAiEA5h1%2BhXMSAVKKhjvcAZ3JU%2FoECFek1D9LtUesx0G6ZkcqlAMIOxABGgw2NzM1ODk4OTc5NTUiDLP6gTNK2iBRQ0QEgCrxAre5ARThtFYiP5HewoKJlDsZ%2Fym9MJOratwTQ9mb3bhJubMItXViaFiSPI8BowsTLnGCxorQFqzSDW9PG05Z4D1jSUBH9Mhn0XE3SM%2BH66V86Tnci%2BdakfPPKnmEzbccndH80Z6m4jfOFQKHWXUuWNb0lBa6WFR9MmesdFj88%2FRRBgooF8chJBXQ9uBZgq%2FAuaY%2Bbyly3iIlMWXpgXUQy1tLuD5Sq7HEF8%2FB5ziU40hTprO%2B2jFPcRPNIhJEFNy%2BJpj%2Fq9ftmp2wYSuTwDF30wnZdZsiVW1pxwjadXMPUEecpeKukqEhtKcyl1IOIlojPFJphRJZZ%2BY0vgBgKhD%2BJZiKG3Kx9FSKT9Dz1sYdfWMQElc6yFFOnZ6R5hpdSHVWxLLdEW8d8S85H5xlSb26Q0JiCNupA4u9jENLdP%2BS02ry0q19vEzYrD%2B%2Fmo6gjXXZa6U66dUlVLSmhl0ZV%2FD17G4DrbZyTZIPv8okvFZpqYvvUTCpivS2BjqcATPuLjpWxhuwUWl1HwkKq2WH3PK4sfLQGRY%2Fmc8xZ0IzU6IDaMosEV%2B4LFr33F1IadIBT9rZVJZ2BBeI6vAQnKMWSeEnjHIXZANw8%2Fk0Kw7DNj46HKVTWfWkDGwH5a3MvBjxo18yawLeYwNSfetGVpS6TMMz8BArcKp7OTbcaLeyXC4Qr%2F0Hoevcuipf9syVdc74eLpb6gIDf9r4Qg%3D%3D)
先ほど作った、最初の行だけ左から順にLEDを点灯させるプログラムをアレンジします。新たに変数「Y」を追加して、次の図の通りプログラムを作りましょう。[《8》回繰り返す]ブロックの内側にさらに[《8》回繰り返す]ブロックを入れます。
![](https://s3.ap-northeast-1.amazonaws.com/spaceblock.jp-storage/inquiries/2024-03-26/dELLx3ic4XNTY3sVJ-BUi.png?AWSAccessKeyId=ASIAZZVIWFLRYPYCASPF&Expires=1725768969&Signature=sXyerg2qBdpxB9aKlg0GI1Yocwo%3D&x-amz-security-token=IQoJb3JpZ2luX2VjEBIaDmFwLW5vcnRoZWFzdC0xIkgwRgIhAMKKk4aPUJn0e3SMDa3%2FAteardhsO4C2QmZ%2FkpDJXcREAiEA5h1%2BhXMSAVKKhjvcAZ3JU%2FoECFek1D9LtUesx0G6ZkcqlAMIOxABGgw2NzM1ODk4OTc5NTUiDLP6gTNK2iBRQ0QEgCrxAre5ARThtFYiP5HewoKJlDsZ%2Fym9MJOratwTQ9mb3bhJubMItXViaFiSPI8BowsTLnGCxorQFqzSDW9PG05Z4D1jSUBH9Mhn0XE3SM%2BH66V86Tnci%2BdakfPPKnmEzbccndH80Z6m4jfOFQKHWXUuWNb0lBa6WFR9MmesdFj88%2FRRBgooF8chJBXQ9uBZgq%2FAuaY%2Bbyly3iIlMWXpgXUQy1tLuD5Sq7HEF8%2FB5ziU40hTprO%2B2jFPcRPNIhJEFNy%2BJpj%2Fq9ftmp2wYSuTwDF30wnZdZsiVW1pxwjadXMPUEecpeKukqEhtKcyl1IOIlojPFJphRJZZ%2BY0vgBgKhD%2BJZiKG3Kx9FSKT9Dz1sYdfWMQElc6yFFOnZ6R5hpdSHVWxLLdEW8d8S85H5xlSb26Q0JiCNupA4u9jENLdP%2BS02ry0q19vEzYrD%2B%2Fmo6gjXXZa6U66dUlVLSmhl0ZV%2FD17G4DrbZyTZIPv8okvFZpqYvvUTCpivS2BjqcATPuLjpWxhuwUWl1HwkKq2WH3PK4sfLQGRY%2Fmc8xZ0IzU6IDaMosEV%2B4LFr33F1IadIBT9rZVJZ2BBeI6vAQnKMWSeEnjHIXZANw8%2Fk0Kw7DNj46HKVTWfWkDGwH5a3MvBjxo18yawLeYwNSfetGVpS6TMMz8BArcKp7OTbcaLeyXC4Qr%2F0Hoevcuipf9syVdc74eLpb6gIDf9r4Qg%3D%3D)
<プログラムの説明>
❶横方向に8個順にLEDを点灯させるプログラムです。x座標に変数「X」入れ、y座標に新たに作った変数「Y」を指定しています。繰り返すたびに、変数「X」が1ずつ増えます。
❷次に指定するLEDの座標を1行下の左端にするためのプログラムです。繰り返すたびに、変数「X」が1にリセットされ、変数「Y」が1ずつ増えます。
プログラムを実行すると、LEDパネルの左上から順に点灯し右端まで8個点灯すると、次の行の左端からまた順番に点灯します。8行目の右端で終わります。
![](https://s3.ap-northeast-1.amazonaws.com/spaceblock.jp-storage/inquiries/2024-03-26/6wdhGRaObgkdF-i45Hm6i.png?AWSAccessKeyId=ASIAZZVIWFLRYPYCASPF&Expires=1725768969&Signature=NtY774tGVu5ACzVdozy8%2BUjTmDs%3D&x-amz-security-token=IQoJb3JpZ2luX2VjEBIaDmFwLW5vcnRoZWFzdC0xIkgwRgIhAMKKk4aPUJn0e3SMDa3%2FAteardhsO4C2QmZ%2FkpDJXcREAiEA5h1%2BhXMSAVKKhjvcAZ3JU%2FoECFek1D9LtUesx0G6ZkcqlAMIOxABGgw2NzM1ODk4OTc5NTUiDLP6gTNK2iBRQ0QEgCrxAre5ARThtFYiP5HewoKJlDsZ%2Fym9MJOratwTQ9mb3bhJubMItXViaFiSPI8BowsTLnGCxorQFqzSDW9PG05Z4D1jSUBH9Mhn0XE3SM%2BH66V86Tnci%2BdakfPPKnmEzbccndH80Z6m4jfOFQKHWXUuWNb0lBa6WFR9MmesdFj88%2FRRBgooF8chJBXQ9uBZgq%2FAuaY%2Bbyly3iIlMWXpgXUQy1tLuD5Sq7HEF8%2FB5ziU40hTprO%2B2jFPcRPNIhJEFNy%2BJpj%2Fq9ftmp2wYSuTwDF30wnZdZsiVW1pxwjadXMPUEecpeKukqEhtKcyl1IOIlojPFJphRJZZ%2BY0vgBgKhD%2BJZiKG3Kx9FSKT9Dz1sYdfWMQElc6yFFOnZ6R5hpdSHVWxLLdEW8d8S85H5xlSb26Q0JiCNupA4u9jENLdP%2BS02ry0q19vEzYrD%2B%2Fmo6gjXXZa6U66dUlVLSmhl0ZV%2FD17G4DrbZyTZIPv8okvFZpqYvvUTCpivS2BjqcATPuLjpWxhuwUWl1HwkKq2WH3PK4sfLQGRY%2Fmc8xZ0IzU6IDaMosEV%2B4LFr33F1IadIBT9rZVJZ2BBeI6vAQnKMWSeEnjHIXZANw8%2Fk0Kw7DNj46HKVTWfWkDGwH5a3MvBjxo18yawLeYwNSfetGVpS6TMMz8BArcKp7OTbcaLeyXC4Qr%2F0Hoevcuipf9syVdc74eLpb6gIDf9r4Qg%3D%3D)
動画でご覧ください。