Arduino UNO 3でmax(最大)を求めて遊ぶ
C++ Arduino アルゴリズム ArduinoUno
目的
マクロを使い配列から最小値をサーチして求める
いろいろ
アルゴリズムの教科書では、
ドラクエ1的に言ったらレベル99で最終章
初期値に最大の値を設定するところがちょつとムズイ
結果
プログラム
#include <Arduino.h>
//min_wo_sagasu_UNO_1
//初期化
// the setup routine runs once when you press reset:
void setup() {
//シリアルポートの初期化
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}//setup
#define n 20
//メインループ
// the loop routine runs over and over again forever:
void loop() {
int a[n] = {
67, 36, 69, 73, 51, 55, 40, 43, 29, 35,
70, 49, 34, 1, 41, 41, 53, 67, 34, 3
};
int min_a = 32767;
for (int i = 0; i < n; i++) {
min_a = min(min_a, a[i]);
}//for
//結果の表示
// print out the value you min:
Serial.println(min_a);
delay(1000); // delay in between reads for stability
}//loop