こないだの Arduinoこたつタイマーのプログラム、インデントがなくて分りにくかったですね。
プログラムをブログにインデント付きで分り易く表示する方法をググりました。
プログラミング練習者のメモ帳
専門学校生の ゆい さん、有難うございます。
CSSとか、タグとか分りませんが、下記の変換を実施しました。
次は貼り付けたいコードを実態参照変換。

↓こちらのサイトで変換を行いました。
HTML実体参照変換 : akiyan.com 
Arduinoエディターからプログラムをコピーして、こちらに張り付け、
変換ボタンを押すだけです。
変換結果を下に貼り付けました。
プログラムの前に、 <pre><code> 、プログラムの後に </code></pre> 
ではさめば作業完了です。
勿論、アメブロの編集エディタはHTMLタグを表示のタブ上で作業して下さいね。
インデントが付いて大分みやすくなりましたねー。
すこしの進歩ですが、大きいですね。
それじゃまったねー。

// こたつタイマープログラム (6分単位/1秒単位)
const int cathode_pins[] = {1,2,3,4,5,0,6};    // カソードに接続const int buttonPin = 7;    // the number of the pushbutton pinconst int LED1  = 13 ;    // LED blink 1sec durationconst int speker = 8 ; //speker on pin 8const int digit1 = 9; // Display digit 1const int digit2 = 10; // Display digit 2const int RELAY_ON = 12; // AC Relay Control//int ledState = HIGH;         // the current state of the output pinint k=0 ;  // Buzzer counterint Count_up =0 ; // Count up state int buttonState;             // the current reading from the input pinint lastButtonState = LOW;   // the previous reading from the input pinconst int number_of_cathode_pins = sizeof(cathode_pins) / sizeof(cathode_pins[0]);// 配列の数int start_num= 20  ;  // Number to countdown from 20min=20*600sec initial 2HOURSint start_num1 = start_num;  // the following variables are long's because the time, measured in miliseconds,// will quickly become a bigger number than can be stored in an int.long lastDebounceTime = 0;  // the last time the output pin was toggledlong debounceDelay = 50;    // the debounce time; increase if the output flickersunsigned long time;// setup() は,最初に一度だけ実行されるvoid setup() {  for (int i = 0; i < number_of_cathode_pins; i++) {    pinMode(cathode_pins[i], OUTPUT);  // cathode_pinsを出力モードに設定する  }  pinMode(digit1, OUTPUT);  pinMode(digit2, OUTPUT);  pinMode(speker, OUTPUT); // speker on pin 8  pinMode(RELAY_ON, OUTPUT);   pinMode(LED1, OUTPUT);   pinMode(buttonPin,INPUT);  // Button Input        // set initial AC Relay State  digitalWrite(RELAY_ON,HIGH);}void loop() {      // read the state of the switch into a local variable:   int reading = digitalRead(buttonPin);  // If the switch changed, due to noise or pressing:   if (reading != lastButtonState) {     // reset the debouncing timer     lastDebounceTime = millis();   }         if ((millis() - lastDebounceTime) > debounceDelay) {     // whatever the reading is at, it's been there for longer     // than the debounce delay, so take it as the actual current state:     // if the button state has changed:    if (reading != buttonState) {       buttonState = reading;       // only increment ciunrter if the new button state is HIGH       if (buttonState == HIGH) {//         ledState = !ledState;//     If button is pressed, increase timer number          if (Count_up == 0 ) {         start_num = start_num + 5 ;// If button is pushed add 30min//             if ((start_num -  (millis()/1000))> 50) { //              start_num = 50 + (millis()/1000) ;//         360sec =6min  Upper Limit = 50 * 6min = 300min (5 Hourrs)           if (start_num - (millis()/360000) > 50 ) {            start_num = (50 + (millis()/360000)) ;            }         }//     If state is count up, restart from initial.         else         {         Count_up = 0;         k = 0;      // Buzzer is Initialized         digitalWrite(RELAY_ON,HIGH); // Power_Relay is ON//         start_num = 10 + (millis()/1000);//      restart from 10 x 6min = 1 Hour         start_num = 10 + (millis()/360000);         }          }     }   }              // save the reading.  Next time through the loop,   // it'll be the lastButtonState:        lastButtonState = reading;  //start_num limitation 50   //long startTime = millis();//  if((millis()/1000) < start_num){//    displayNumber(start_num -(millis()/1000));// 360sec =6 min =36000 millis() count   if((millis()/360000) < start_num){    displayNumber(start_num -(millis()/360000));     if ((millis()/500)% 2 == 1 ) {      digitalWrite(LED1, HIGH);     }    else {      digitalWrite(LED1, LOW);      }  }  else  {    // reached zero, flash the display    Count_up =1; // count up state    k=k+1;   // count_up buzzer count    time=millis();    while(millis() < time+200) {      displayNumber(0);  // display 0 for 0.2 second      digitalWrite(RELAY_ON,LOW); //TIME UP Relay OFF     if(k<6) { tone (8, 1000, 100);     }    }    time=millis();        while(millis() < time+200) {      lightNumber(10);  // Turn display off for 0.2 second    }  }  }// 2ケタの表示を計算するvoid displayNumber(int toDisplay) {  long beginTime = millis();  for(int digit = 2 ; digit > 0 ; digit--) {    //Turn on a digit for a short amount of time    switch(digit) {    case 1:      digitalWrite(digit1, HIGH);      break;        case 2:      digitalWrite(digit2, HIGH);      break;    }//Turn on the right segments for this digit//    lightNumber(toDisplay % 6);//    toDisplay /= 6;    lightNumber(toDisplay % 10);    toDisplay /= 10;//    delayMicroseconds(DISPLAY_BRIGHTNESS);     //Display digit for fraction of a second (1us to 5000us, 500 is pretty good)    //Turn off all segments    delay(2) ;    lightNumber(0);     //Turn off all digits    digitalWrite(digit1, LOW);    digitalWrite(digit2, LOW);  }////  while( (millis() - beginTime) < 10) ;   //Wait for 20ms to pass before we paint the display again}// 7SEG表示パターンconst int digits[] = {  0b00111111, // 0  0b00000110, // 1  0b01011011, // 2  0b01001111, // 3  0b01100110, // 4  0b01101101, // 5  0b01111101, // 6  0b00100111, // 7  0b01111111, // 8  0b01101111, // 9  0b00000000, // 10}; // 1けたの数字(n)を表示するvoid lightNumber (int n) {  for (int i = 0; i < number_of_cathode_pins; i++) {    digitalWrite(cathode_pins[i], digits[n] & (1 << i) ? LOW : HIGH);  }}
}

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です