meta data for this page
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
arduino:code_collection [2025/03/22 19:49] – [TON] vamsan | arduino:code_collection [2025/03/22 22:54] (current) – [Float to char[]] vamsan | ||
---|---|---|---|
Line 4: | Line 4: | ||
<code c> | <code c> | ||
// var def block | // var def block | ||
- | unsigned long startMillis, | + | unsigned long startMillis, |
- | const unsigned long period = 2000; | + | const unsigned long period = 2000; // the value is a number of milliseconds |
// code block | // code block | ||
- | currentMillis = millis(); | + | currentMillis = millis(); |
- | if (currentMillis - startMillis >= period) | + | if (currentMillis - startMillis >= period) |
{ | { | ||
- | startMillis = currentMillis; | + | startMillis = currentMillis; |
// after time has elapsed the call | // after time has elapsed the call | ||
+ | // ... | ||
} | } | ||
+ | </ | ||
+ | |||
+ | ==== check serial monitor ==== | ||
+ | <code c> | ||
+ | |||
+ | // code in setup() | ||
+ | Serial.begin(9600); | ||
+ | | ||
+ | while (!Serial) { | ||
+ | ; // wait for serial port to connect. Needed for native USB port only | ||
+ | } | ||
+ | Serial.println(" | ||
+ | </ | ||
+ | ===== Converting code collection ===== | ||
+ | ==== Float to char[] ==== | ||
+ | <code c> | ||
+ | // lib init (optional) | ||
+ | #include " | ||
+ | // converting | ||
+ | float a; | ||
+ | char sendValue[10]; | ||
+ | dtostrf (a, 10, 8, sendValue); // float_value, | ||
+ | |||
+ | </ | ||
+ | |||
+ | ==== Int to char[] ==== | ||
+ | <code c> | ||
+ | int a; | ||
+ | char sendValue[10]; | ||
+ | itoa (i, | ||
+ | // base: Numerical base used to represent the value as a string, between 2 and 36, where 10 means decimal base, 16 hexadecimal, | ||
+ | |||
+ | </ | ||
+ | ==== String to char[] ==== | ||
+ | <code c> | ||
+ | |||
+ | char place[20]; | ||
+ | strcpy(place," | ||
+ | |||
</ | </ | ||
===== Modbus code collection ===== | ===== Modbus code collection ===== |