跳到主要內容

程式設計-C語言 / OLD / 訊二甲( 江 ) / 上學期 / 1115-C++基礎 bool 資料型態

bool型別的變數只能儲存0或是1而且bool資料型別只使用一個位元組。

1

1

 

1

 

#include
#include
using namespace std;
 
int main()
{
    bool a = true; //bool a = 1;
    bool b = false; //bool b = false;
    cout << "a = " << a << endl;          
    cout << "b = " << b << endl;                 
}
 
1
 
1
 
/*
 * Uno pin{0,1} for UART, should not be used
 */
#define TOTAL_PIN 18
char SW[] = {2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};
//           0 1 2 3 4 5 6 7  8  9 10 11 12 13 14 15 16 17
char SW_Pressed( char swno );
char s[50];
//---------------------------------------------------------
void loop() {     //
  static int i = 2;
  if ( SW_Pressed( SW[i] )) {
    sprintf( s, "SW%d Pressed\n", SW[i] );
    Serial.print( s );
  }
  if ( ++i >= 18 ) i = 2;
}
void setup() {
  Serial.begin(115200);
  Serial.print( "\n Hello World \n" );
}
 
//-------------------------------------------------------
// 瘥?30mS瑼X1甈?
char SW_Pressed( char swno ) {
    #define dT 30 //mS
    static long inited = 0;   //Is every bit initialized? 0/1:n/y
    static long bHiVolt=-1, old = 0;
    char rc = false;  //?身? false(瘝??)
    if ( !(inited & 1L<
        inited = inited | 1L<
        pinMode( inited , INPUT_PULLUP);
    }
    if ( millis() - old >= dT ) {
        digitalWrite( swno, HIGH );//?踹?瘚格???圈隤方???
        if ( !digitalRead( swno ) ) {
            if ( bHiVolt & (1L<
              bHiVolt &= ~(1L<
              rc  = true;
              old = millis(); //???菔◤??嚗??脣?????
            }
        } else {
            bHiVolt |= 1L<
        }
    }
    return rc;
}
//-------------------------------------------------------

 

 

時間類別單位標題發佈點閱
跳至網頁頂部