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