我正在尝试启动并运行一个小型BMP085气压计项目.我希望能够在不同的操作模式(MODE_PRESSURE和MODE_ALT)之间切换.我有MODE_PRESSURE并MODE_ALT定义为const int.
const int MODE_PRESSURE = 1; // display pressure and temp
const int MODE_ALT = 2; // display altitude relative to sea level
int mode; // stores the current mode
void setup {
mode = MODE_PRESSURE;
}
void loop {
// Read mode button and set mode accordingly
int buttonPressed = readButtons();
switch(buttonPressed) {
case BTN_MODE:
if(mode == MODE_PRESSURE) { mode = MODE_ALT; }
if(mode == MODE_ALT) { mode = MODE_PRESSURE; }
Serial.println(mode); …Run Code Online (Sandbox Code Playgroud)