test
Dependencies: HMC6352 PID mbed
Fork of ver1_2_2 by
wordString.cpp@0:74bf4953c0d1, 2013-03-09 (annotated)
- Committer:
- akudohune
- Date:
- Sat Mar 09 10:11:06 2013 +0000
- Revision:
- 0:74bf4953c0d1
ver1_2_2;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
akudohune | 0:74bf4953c0d1 | 1 | |
akudohune | 0:74bf4953c0d1 | 2 | #include <sstream> |
akudohune | 0:74bf4953c0d1 | 3 | #include "mbed.h" |
akudohune | 0:74bf4953c0d1 | 4 | |
akudohune | 0:74bf4953c0d1 | 5 | string StringFIN; |
akudohune | 0:74bf4953c0d1 | 6 | |
akudohune | 0:74bf4953c0d1 | 7 | using namespace std; |
akudohune | 0:74bf4953c0d1 | 8 | |
akudohune | 0:74bf4953c0d1 | 9 | |
akudohune | 0:74bf4953c0d1 | 10 | extern Serial pc; // tx, rx |
akudohune | 0:74bf4953c0d1 | 11 | |
akudohune | 0:74bf4953c0d1 | 12 | string IntToString(int number) |
akudohune | 0:74bf4953c0d1 | 13 | { |
akudohune | 0:74bf4953c0d1 | 14 | stringstream ss; |
akudohune | 0:74bf4953c0d1 | 15 | ss << number; |
akudohune | 0:74bf4953c0d1 | 16 | return ss.str(); |
akudohune | 0:74bf4953c0d1 | 17 | } |
akudohune | 0:74bf4953c0d1 | 18 | |
akudohune | 0:74bf4953c0d1 | 19 | void array(int power1,int power2,int power3,int power4) |
akudohune | 0:74bf4953c0d1 | 20 | { |
akudohune | 0:74bf4953c0d1 | 21 | int input[4] = {power1,power2,power3,power4}; |
akudohune | 0:74bf4953c0d1 | 22 | int value = 0; |
akudohune | 0:74bf4953c0d1 | 23 | string StringA[4] = {"0","0","0","0"}; |
akudohune | 0:74bf4953c0d1 | 24 | |
akudohune | 0:74bf4953c0d1 | 25 | |
akudohune | 0:74bf4953c0d1 | 26 | string StringX = "0"; |
akudohune | 0:74bf4953c0d1 | 27 | string StringY = "0"; |
akudohune | 0:74bf4953c0d1 | 28 | string StringZ = "0"; |
akudohune | 0:74bf4953c0d1 | 29 | string String0 = "0"; |
akudohune | 0:74bf4953c0d1 | 30 | |
akudohune | 0:74bf4953c0d1 | 31 | StringFIN = "0"; |
akudohune | 0:74bf4953c0d1 | 32 | |
akudohune | 0:74bf4953c0d1 | 33 | for(uint8_t i = 0 ; i < 4; i++){ |
akudohune | 0:74bf4953c0d1 | 34 | |
akudohune | 0:74bf4953c0d1 | 35 | value = input[i]; |
akudohune | 0:74bf4953c0d1 | 36 | |
akudohune | 0:74bf4953c0d1 | 37 | StringX = IntToString(i+1); |
akudohune | 0:74bf4953c0d1 | 38 | |
akudohune | 0:74bf4953c0d1 | 39 | if( (value < 0) && (value >= -100) ){ |
akudohune | 0:74bf4953c0d1 | 40 | StringY = "R"; |
akudohune | 0:74bf4953c0d1 | 41 | value = abs(value); |
akudohune | 0:74bf4953c0d1 | 42 | StringZ = IntToString(value); |
akudohune | 0:74bf4953c0d1 | 43 | }else if( (value >= 0) && (value <= 100) ){ |
akudohune | 0:74bf4953c0d1 | 44 | StringY = "F"; |
akudohune | 0:74bf4953c0d1 | 45 | StringZ = IntToString(value); |
akudohune | 0:74bf4953c0d1 | 46 | }else{ |
akudohune | 0:74bf4953c0d1 | 47 | StringA[i] = StringX + "F" + "000"; |
akudohune | 0:74bf4953c0d1 | 48 | |
akudohune | 0:74bf4953c0d1 | 49 | } |
akudohune | 0:74bf4953c0d1 | 50 | |
akudohune | 0:74bf4953c0d1 | 51 | if(value < 10){ |
akudohune | 0:74bf4953c0d1 | 52 | String0 = "00"; |
akudohune | 0:74bf4953c0d1 | 53 | StringZ = String0 + StringZ; |
akudohune | 0:74bf4953c0d1 | 54 | }else if(value < 100) |
akudohune | 0:74bf4953c0d1 | 55 | { |
akudohune | 0:74bf4953c0d1 | 56 | String0 = "0"; |
akudohune | 0:74bf4953c0d1 | 57 | StringZ = String0 + StringZ; |
akudohune | 0:74bf4953c0d1 | 58 | }else{ |
akudohune | 0:74bf4953c0d1 | 59 | |
akudohune | 0:74bf4953c0d1 | 60 | } |
akudohune | 0:74bf4953c0d1 | 61 | |
akudohune | 0:74bf4953c0d1 | 62 | StringA[i] = (StringX + StringY + StringZ); |
akudohune | 0:74bf4953c0d1 | 63 | |
akudohune | 0:74bf4953c0d1 | 64 | if(i == 0)StringFIN = StringA[i]; |
akudohune | 0:74bf4953c0d1 | 65 | else StringFIN += StringA[i]; |
akudohune | 0:74bf4953c0d1 | 66 | |
akudohune | 0:74bf4953c0d1 | 67 | } |
akudohune | 0:74bf4953c0d1 | 68 | |
akudohune | 0:74bf4953c0d1 | 69 | StringFIN += "\r\n"; |
akudohune | 0:74bf4953c0d1 | 70 | } |