User Tools

Site Tools


en-us_commands:reference:ictu

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
en-us_commands:reference:ictu [2026/09/07 23:35] – 바깥 편집 127.0.0.1en-us_commands:reference:ictu [2026/09/08 00:53] (current) – 바깥 편집 127.0.0.1
Line 10: Line 10:
  
 ^ Command ^ Arguments ^ Return Value ^ Operation ^ ^ Command ^ Arguments ^ Return Value ^ Operation ^
-| ''Ictu(counter_id, CU, RESET, PV)'' | ''uint8_t counter_id'' — Counter numberSupports ''0'' ~ ''255'', the ''uint8_t'' range\\ ''bool CU''\\ ''bool RESET''\\ ''int32_t PV'' — Preset value | ''bool''Counts input rising edges and returns true when the preset value is reached. |+| ''Ictu(counter_id, CU, RESET, PV)'' | ''uint8_t counter_id'' — Counter identifierUse the same number for the same counting task\\ ''bool CU'' — Count input. Increments by 1 when it changes from LOW to HIGH\\ ''bool RESET'' — When true, reset the current count to 0\\ ''int32_t PV'' — Target count. Returns true when the current count reaches or exceeds this value | ''bool''Count rising input edges and return true when the preset is reached. | 
 + 
 +**Beginner-friendly explanation** 
 + 
 +''Ictu()'' does not measure how long a sensor stays on. It counts how many times the sensor changes from ''LOW'' to ''HIGH''. For example, when one item passes the sensor, the input changes ''LOW → HIGH → LOW'' and the counter increases by 1. A sensor that remains ''HIGH'' is counted only once. 
 + 
 +Read the call ''Ictu(counter_id, CU, RESET, PV)'' as follows. 
 + 
 +  * ''counter_id'': Identifies one counter among several counters. Always use the same number for the same counting task. 
 +  * ''CU'': The count input. The current count increases by 1 when this input changes from ''LOW → HIGH''
 +  * ''RESET'': When ''true'', clears the current count to 0. While RESET is active, CU is not counted even if it turns on. 
 +  * ''PV'': The target count. The return value becomes ''true'' when the current count reaches or exceeds this value. 
 + 
 +Call it continuously from ''loop()'' so it can detect input changes. The example below counts five items with input 0 and turns on the board's status LED when the target is reached. Pressing the reset button on input 1 starts the count again from zero.
  
  
Line 17: Line 30:
 <code cpp> <code cpp>
 const uint8_t COUNTER_ID = 0; const uint8_t COUNTER_ID = 0;
-const int32_t BOX_CAPACITY = 20;+const uint8_t ITEM_SENSOR_PIN = 0; 
 +const uint8_t RESET_BUTTON_PIN = 1; 
 +const uint8_t FULL_LAMP_PIN = LED_BUILTIN; 
 +const int32_t BOX_CAPACITY = 5;
  
 void setup() { void setup() {
Line 24: Line 40:
  
 void loop() { void loop() {
-  const bool itemSensor = IdigitalRead(0, 5);  // Read the input repeatedly and update only if all samples match. If HIGH and LOW are mixed, retain the previous stable state. +  const bool itemSensor = digitalRead(ITEM_SENSOR_PIN== HIGH; 
-  const bool resetButton = IdigitalRead(1, 5);  // Read the input repeatedly and update only if all samples match. If HIGH and LOW are mixed, retain the previous stable state.+  const bool resetButton = digitalRead(RESET_BUTTON_PIN== HIGH;
   const bool boxFull = Ictu(COUNTER_ID, itemSensor, resetButton, BOX_CAPACITY);  // Count rising input edges and return true when the preset is reached.   const bool boxFull = Ictu(COUNTER_ID, itemSensor, resetButton, BOX_CAPACITY);  // Count rising input edges and return true when the preset is reached.
-  digitalWrite(32, boxFull ? HIGH : LOW);+  digitalWrite(FULL_LAMP_PIN, boxFull ? HIGH : LOW)
 + 
 +  static bool previousBoxFull = false; 
 +  if (boxFull && !previousBoxFull) { 
 +    Serial.println(F("5 items counted: box is full")); 
 +  } 
 +  previousBoxFull = boxFull;
 } }
 </code> </code>
Line 33: Line 55:
 ===== Precautions ===== ===== Precautions =====
  
-  * The previous fixed 0~31 restriction has been removedHowever, the argument type is ''uint8_t'', so the maximum ID is ''255''+  * ''CU'' counts only ''LOW → HIGH'' transitionsIf the signal remains ''HIGH'', the count increases only once. 
-  * If insufficient memory prevents allocation of counter state, counter commands return ''false'' or ''0''+  * When ''RESET'' is ''true'', the current count is cleared to 0 and ''CU'' is not counted during that call
-  * Once createdcounter state is retained while the program runs.+  * Set ''PV'' to a target count of 1 or greater. If ''PV'' is or less, the initial count of 0 is already considered to have reached the target. 
 +  * Input changes can be missed when sensor pulses are faster than ''loop()''. Use the product's high-speed counter for fast pulses
 +  * Use a different ''counter_id'' for each counting task. Do not share one number among CTUCTD, and CTUD. 
 +  * Use ''IgetCount()'' with the same ''counter_id'' only when you need the current count. 
 + 
 +===== Built-in Commands in the Same Category ===== 
 + 
 +  * [[:en-us_commands:reference:ictd|Ictd() View detailed description]] 
 +  * [[:en-us_commands:reference:ictud|Ictud() View detailed description]] 
 +  * [[:en-us_commands:reference:igetcount|IgetCount() View detailed description]] 
 +  * [[:en-us_commands:reference:isetcount|IsetCount() View detailed description]] 
 +  * [[:en-us_commands:reference:ictuddownstate|IctudDownState() View detailed description]]
  
 [[:en-us_commands:builtin|← Built-in Command List]] [[:en-us_commands:builtin|← Built-in Command List]]
  
en-us_commands/reference/ictu.1788791734.txt.gz · Last modified: by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki