Arduinoの光センサ(CdSセル5mmタイプ使用)で読み取った値に応じて、Processingでおみくじを表示させるプログラムを書いています。Arduinoの光センサからその数値をProcessingに表示することはできています。
しかしながら、条件分岐で
「センサの値がいくつ以上+乱数を発生させておみくじ結果を表示」
しようとすると以下のコードでは最初に読み込んだ画像しか表示されず、おみくじ結果が表示されません。
Processing
1/* 2 * Arduino - Processingシリアル通信 3 * Firmataを使用したコード 4 * Processing側 5 */ 6 7PImage img; 8 9import processing.serial.*; 10import cc.arduino.*; 11Arduino arduino; 12int input0 = 0; 13 14 15void setup() { 16 size(500, 800); 17 noStroke(); 18 arduino = new Arduino(this, Arduino.list()[1], 57600); 19 img = loadImage("omikuji.jpg"); 20 image(img, 0, 0); 21 22 int analog0 = arduino.analogRead(input0); 23 if (analog0 > 990) { 24 int r = (int)random(0, 3); 25 if (r == 0 ) { 26 text("中吉", 30, 20, 30, 350); 27 } 28 if (r == 1) { 29 text("大吉", 30, 20, 30, 350); 30 } 31 if (r == 2) { 32 text("小吉", 30, 20, 30, 350); 33 } 34 if (r == 3) { 35 text("末吉", 30, 20, 30, 350); 36 } 37 } 38} 39 40void draw() { 41} 42
void draw()内に以下の部分を書くと、センサで990以上の値を毎回読み取るたびに、書かれてしまって、文字が読めないという問題が発生しています。
Processing
1int analog0 = arduino.analogRead(input0); 2 if (analog0 > 990) { 3 int r = (int)random(0, 3); 4 if (r == 0 ) { 5 text("中吉", 30, 20, 30, 350); 6 } 7 if (r == 1) { 8 text("大吉", 30, 20, 30, 350); 9 } 10 if (r == 2) { 11 text("小吉", 30, 20, 30, 350); 12 } 13 if (r == 3) { 14 text("末吉", 30, 20, 30, 350); 15 } 16 }
ご回答やアドバイスをいただけましたら幸いです。どうぞよろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2017/07/01 05:30
退会済みユーザー
2017/07/01 10:52