User Tools

Site Tools


en-us_commands:reference:iscale

Differences

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

Link to this comparison view

Next revision
Previous revision
en-us_commands:reference:iscale [2026/09/07 21:52] – 만듦 - 바깥 편집 127.0.0.1en-us_commands:reference:iscale [2026/09/08 00:53] (current) – 바깥 편집 127.0.0.1
Line 16: Line 16:
  
 <code cpp> <code cpp>
 +void setup() {
 +  Serial.begin(115200);
 +}
 +
 void loop() { void loop() {
-  int32_t raw = (int32_t)analogRead(A0); +  uint16_t raw2 analogRead2(0);  // Read the 4–20mA-adjusted input value of the specified channel. 
-  int32_t percent Iscale(raw, 0, 1023, 0, 100); +  int32_t filtered2 analogRead2Avg(0, 5);  // Return the integer average of 4–20mA input values. 
-  float voltage Iscalef((float)raw, 0.0F1023.0F, 0.0F, 5.0F);+  float filtered2f = analogRead2Avgf(0, 5);  // Return the floating-point average of 4–20mA input values. 
 +  float currentmA IanalogRead2f(0, 4.0F, 20.0F);  // Map the 4–20mA input value to the specified floating-point range.
  
 +  if (raw2 == ANALOG_READ2_ERROR || filtered2 == ANALOG_READ2_AVG_ERROR ||
 +      filtered2f == (float)ANALOG_READ2_AVG_ERROR ||
 +      currentmA == (float)ANALOG_READ2_ERROR) {
 +    Serial.println("4-20mA input error");
 +    delay(500);
 +    return;
 +  }
 +
 +  int32_t percent = Iscale((int32_t)raw2, 0, 32767, 0, 100);  // Map an integer input to the specified integer range.
 +
 +  IanalogWrite2(0, 0, 100, 50);       // 50% → approx. 12mA
 +  IanalogWrite2f(1, 0.0F, 10.0F, 2.5F); // 25% → approx. 8mA
 +
 +  Serial.print("4-20mA raw: ");
 +  Serial.println(raw2);
 +  Serial.print("4-20mA filtered: ");
 +  Serial.println(filtered2);
 +  Serial.print("4-20mA filtered float: ");
 +  Serial.println(filtered2f, 2);
 +  Serial.print("percent: ");
   Serial.println(percent);   Serial.println(percent);
-  Serial.println(voltage, 2);+  Serial.print("current: "); 
 +  Serial.println(currentmA, 2); 
 + 
 +  delay(500);
 } }
 </code> </code>
Line 31: Line 59:
   * Out-of-range inputs are clamped to the nearest output endpoint.   * Out-of-range inputs are clamped to the nearest output endpoint.
   * Both commands perform only linear range conversion. They do not replace sensor calibration or electrical protection.   * Both commands perform only linear range conversion. They do not replace sensor calibration or electrical protection.
 +
 +===== Built-in Commands in the Same Category =====
 +
 +  * [[:en-us_commands:reference:iscalef|Iscalef() View detailed description]]
  
 [[:en-us_commands:builtin|← Built-in Command List]] [[:en-us_commands:builtin|← Built-in Command List]]
  
en-us_commands/reference/iscale.1788785568.txt.gz · Last modified: by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki