Junichi Katsu
/
wallbotLED_base
うおーるぼっとLEDのワークショップ用
wallbotLED/wallbotLED.cpp@0:9fcc79b3f00e, 2017-02-03 (annotated)
- Committer:
- jksoft
- Date:
- Fri Feb 03 06:26:54 2017 +0000
- Revision:
- 0:9fcc79b3f00e
- Child:
- 1:b9cd4ab5ead7
??
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jksoft | 0:9fcc79b3f00e | 1 | /* JKsoft Wallbot LED Library |
jksoft | 0:9fcc79b3f00e | 2 | * |
jksoft | 0:9fcc79b3f00e | 3 | * wallbotLED.cpp |
jksoft | 0:9fcc79b3f00e | 4 | * |
jksoft | 0:9fcc79b3f00e | 5 | * Copyright (c) 2010-2016 jksoft |
jksoft | 0:9fcc79b3f00e | 6 | * |
jksoft | 0:9fcc79b3f00e | 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
jksoft | 0:9fcc79b3f00e | 8 | * of this software and associated documentation files (the "Software"), to deal |
jksoft | 0:9fcc79b3f00e | 9 | * in the Software without restriction, including without limitation the rights |
jksoft | 0:9fcc79b3f00e | 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
jksoft | 0:9fcc79b3f00e | 11 | * copies of the Software, and to permit persons to whom the Software is |
jksoft | 0:9fcc79b3f00e | 12 | * furnished to do so, subject to the following conditions: |
jksoft | 0:9fcc79b3f00e | 13 | * |
jksoft | 0:9fcc79b3f00e | 14 | * The above copyright notice and this permission notice shall be included in |
jksoft | 0:9fcc79b3f00e | 15 | * all copies or substantial portions of the Software. |
jksoft | 0:9fcc79b3f00e | 16 | * |
jksoft | 0:9fcc79b3f00e | 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
jksoft | 0:9fcc79b3f00e | 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
jksoft | 0:9fcc79b3f00e | 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
jksoft | 0:9fcc79b3f00e | 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
jksoft | 0:9fcc79b3f00e | 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
jksoft | 0:9fcc79b3f00e | 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
jksoft | 0:9fcc79b3f00e | 23 | * THE SOFTWARE. |
jksoft | 0:9fcc79b3f00e | 24 | */ |
jksoft | 0:9fcc79b3f00e | 25 | |
jksoft | 0:9fcc79b3f00e | 26 | #include "mbed.h" |
jksoft | 0:9fcc79b3f00e | 27 | #include "wallbotLED.h" |
jksoft | 0:9fcc79b3f00e | 28 | |
jksoft | 0:9fcc79b3f00e | 29 | |
jksoft | 0:9fcc79b3f00e | 30 | wallbotLED::wallbotLED() : _right(P0_28,P0_30,P0_0) , _left(P0_29,P0_23,P0_24) , |
jksoft | 0:9fcc79b3f00e | 31 | _i2c(P0_22,P0_21), _matrix1(&_i2c),_matrix2(&_i2c), |
jksoft | 0:9fcc79b3f00e | 32 | _sw(P0_16,P0_17), |
jksoft | 0:9fcc79b3f00e | 33 | _outlow(P0_20),_statusled(P0_18,P0_19), |
jksoft | 0:9fcc79b3f00e | 34 | _f_sensor1(P0_2),_f_sensor2(P0_3), |
jksoft | 0:9fcc79b3f00e | 35 | _f_sensor3(P0_4),_f_sensor4(P0_5) { |
jksoft | 0:9fcc79b3f00e | 36 | _right = 0.0; |
jksoft | 0:9fcc79b3f00e | 37 | _left = 0.0; |
jksoft | 0:9fcc79b3f00e | 38 | _outlow = 0; |
jksoft | 0:9fcc79b3f00e | 39 | _statusled = 0x3; |
jksoft | 0:9fcc79b3f00e | 40 | SetFloorSensorGain(SENSOR_VAL_GAIN_DEFAULT); |
jksoft | 0:9fcc79b3f00e | 41 | _mpu.initialize(); |
jksoft | 0:9fcc79b3f00e | 42 | _sw.mode(PullUp); |
jksoft | 0:9fcc79b3f00e | 43 | //_matrix1.begin(0x71); |
jksoft | 0:9fcc79b3f00e | 44 | _matrix1.begin(0x74); |
jksoft | 0:9fcc79b3f00e | 45 | _matrix2.begin(0x70); |
jksoft | 0:9fcc79b3f00e | 46 | _matrix1.clear(); |
jksoft | 0:9fcc79b3f00e | 47 | _matrix2.clear(); |
jksoft | 0:9fcc79b3f00e | 48 | for(int i = 0 ; i < 4 ; i++) |
jksoft | 0:9fcc79b3f00e | 49 | { |
jksoft | 0:9fcc79b3f00e | 50 | _sensor_def[i] = SENSOR_VAL_DEFAULT; |
jksoft | 0:9fcc79b3f00e | 51 | } |
jksoft | 0:9fcc79b3f00e | 52 | } |
jksoft | 0:9fcc79b3f00e | 53 | |
jksoft | 0:9fcc79b3f00e | 54 | void wallbotLED::driveLeftMotor(float speed) { |
jksoft | 0:9fcc79b3f00e | 55 | _left = speed; |
jksoft | 0:9fcc79b3f00e | 56 | } |
jksoft | 0:9fcc79b3f00e | 57 | |
jksoft | 0:9fcc79b3f00e | 58 | void wallbotLED::driveRightMotor(float speed) { |
jksoft | 0:9fcc79b3f00e | 59 | _right = speed; |
jksoft | 0:9fcc79b3f00e | 60 | } |
jksoft | 0:9fcc79b3f00e | 61 | |
jksoft | 0:9fcc79b3f00e | 62 | void wallbotLED::driveMotor(float r_speed,float l_speed) { |
jksoft | 0:9fcc79b3f00e | 63 | driveRightMotor(r_speed); |
jksoft | 0:9fcc79b3f00e | 64 | driveLeftMotor(l_speed); |
jksoft | 0:9fcc79b3f00e | 65 | } |
jksoft | 0:9fcc79b3f00e | 66 | |
jksoft | 0:9fcc79b3f00e | 67 | void wallbotLED::driveMotor(int r_speed,int l_speed) { |
jksoft | 0:9fcc79b3f00e | 68 | driveRightMotor(r_speed/100.0); |
jksoft | 0:9fcc79b3f00e | 69 | driveLeftMotor(l_speed/100.0); |
jksoft | 0:9fcc79b3f00e | 70 | } |
jksoft | 0:9fcc79b3f00e | 71 | |
jksoft | 0:9fcc79b3f00e | 72 | void wallbotLED::forward(float speed) { |
jksoft | 0:9fcc79b3f00e | 73 | driveLeftMotor(speed); |
jksoft | 0:9fcc79b3f00e | 74 | driveRightMotor(speed); |
jksoft | 0:9fcc79b3f00e | 75 | } |
jksoft | 0:9fcc79b3f00e | 76 | |
jksoft | 0:9fcc79b3f00e | 77 | void wallbotLED::backward(float speed) { |
jksoft | 0:9fcc79b3f00e | 78 | driveLeftMotor(-speed); |
jksoft | 0:9fcc79b3f00e | 79 | driveRightMotor(-speed); |
jksoft | 0:9fcc79b3f00e | 80 | } |
jksoft | 0:9fcc79b3f00e | 81 | |
jksoft | 0:9fcc79b3f00e | 82 | void wallbotLED::leftTurn(float speed) { |
jksoft | 0:9fcc79b3f00e | 83 | driveLeftMotor(-speed); |
jksoft | 0:9fcc79b3f00e | 84 | driveRightMotor(speed); |
jksoft | 0:9fcc79b3f00e | 85 | } |
jksoft | 0:9fcc79b3f00e | 86 | |
jksoft | 0:9fcc79b3f00e | 87 | void wallbotLED::rightTurn(float speed) { |
jksoft | 0:9fcc79b3f00e | 88 | driveLeftMotor(speed); |
jksoft | 0:9fcc79b3f00e | 89 | driveRightMotor(-speed); |
jksoft | 0:9fcc79b3f00e | 90 | } |
jksoft | 0:9fcc79b3f00e | 91 | |
jksoft | 0:9fcc79b3f00e | 92 | void wallbotLED::stop(void) { |
jksoft | 0:9fcc79b3f00e | 93 | driveLeftMotor(0.0); |
jksoft | 0:9fcc79b3f00e | 94 | driveRightMotor(0.0); |
jksoft | 0:9fcc79b3f00e | 95 | } |
jksoft | 0:9fcc79b3f00e | 96 | |
jksoft | 0:9fcc79b3f00e | 97 | void wallbotLED::SetLed(int bit) { |
jksoft | 0:9fcc79b3f00e | 98 | bit |= bit >> 2; |
jksoft | 0:9fcc79b3f00e | 99 | _statusled = (bit ^ 0x03) & 0x03; |
jksoft | 0:9fcc79b3f00e | 100 | } |
jksoft | 0:9fcc79b3f00e | 101 | |
jksoft | 0:9fcc79b3f00e | 102 | void wallbotLED::SetLed1(int bit) { |
jksoft | 0:9fcc79b3f00e | 103 | if( bit ) |
jksoft | 0:9fcc79b3f00e | 104 | { |
jksoft | 0:9fcc79b3f00e | 105 | bit = _statusled ^ 0x03; |
jksoft | 0:9fcc79b3f00e | 106 | bit = bit | 0x1; |
jksoft | 0:9fcc79b3f00e | 107 | } |
jksoft | 0:9fcc79b3f00e | 108 | else |
jksoft | 0:9fcc79b3f00e | 109 | { |
jksoft | 0:9fcc79b3f00e | 110 | bit = _statusled ^ 0x03; |
jksoft | 0:9fcc79b3f00e | 111 | bit = bit & 0x2; |
jksoft | 0:9fcc79b3f00e | 112 | } |
jksoft | 0:9fcc79b3f00e | 113 | SetLed(bit); |
jksoft | 0:9fcc79b3f00e | 114 | } |
jksoft | 0:9fcc79b3f00e | 115 | |
jksoft | 0:9fcc79b3f00e | 116 | void wallbotLED::SetLed2(int bit) { |
jksoft | 0:9fcc79b3f00e | 117 | if( bit ) |
jksoft | 0:9fcc79b3f00e | 118 | { |
jksoft | 0:9fcc79b3f00e | 119 | bit = _statusled ^ 0x03; |
jksoft | 0:9fcc79b3f00e | 120 | bit = bit | 0x2; |
jksoft | 0:9fcc79b3f00e | 121 | } |
jksoft | 0:9fcc79b3f00e | 122 | else |
jksoft | 0:9fcc79b3f00e | 123 | { |
jksoft | 0:9fcc79b3f00e | 124 | bit = _statusled ^ 0x03; |
jksoft | 0:9fcc79b3f00e | 125 | bit = bit & 0x1; |
jksoft | 0:9fcc79b3f00e | 126 | } |
jksoft | 0:9fcc79b3f00e | 127 | SetLed(bit); |
jksoft | 0:9fcc79b3f00e | 128 | } |
jksoft | 0:9fcc79b3f00e | 129 | |
jksoft | 0:9fcc79b3f00e | 130 | void wallbotLED::SetFloorSensorGain(int gain) { |
jksoft | 0:9fcc79b3f00e | 131 | _sensor_gain = gain; |
jksoft | 0:9fcc79b3f00e | 132 | } |
jksoft | 0:9fcc79b3f00e | 133 | |
jksoft | 0:9fcc79b3f00e | 134 | void wallbotLED::FloorSensorCalibrate(void) { |
jksoft | 0:9fcc79b3f00e | 135 | |
jksoft | 0:9fcc79b3f00e | 136 | for(int i = 0 ; i < 4 ; i++) |
jksoft | 0:9fcc79b3f00e | 137 | { |
jksoft | 0:9fcc79b3f00e | 138 | _sensor_def[i] = 0; |
jksoft | 0:9fcc79b3f00e | 139 | } |
jksoft | 0:9fcc79b3f00e | 140 | |
jksoft | 0:9fcc79b3f00e | 141 | for(int j = 0 ; j < 12 ; j++) |
jksoft | 0:9fcc79b3f00e | 142 | { |
jksoft | 0:9fcc79b3f00e | 143 | int in[4] = { _f_sensor1.read_u16(), |
jksoft | 0:9fcc79b3f00e | 144 | _f_sensor2.read_u16(), |
jksoft | 0:9fcc79b3f00e | 145 | _f_sensor3.read_u16(), |
jksoft | 0:9fcc79b3f00e | 146 | _f_sensor4.read_u16() |
jksoft | 0:9fcc79b3f00e | 147 | }; |
jksoft | 0:9fcc79b3f00e | 148 | SetLed(1<<(j%2)); |
jksoft | 0:9fcc79b3f00e | 149 | for(int i = 0 ; i < 4 ; i++) |
jksoft | 0:9fcc79b3f00e | 150 | { |
jksoft | 0:9fcc79b3f00e | 151 | _sensor_def[i] += in[i]; |
jksoft | 0:9fcc79b3f00e | 152 | } |
jksoft | 0:9fcc79b3f00e | 153 | wait_ms(200); |
jksoft | 0:9fcc79b3f00e | 154 | } |
jksoft | 0:9fcc79b3f00e | 155 | for(int i = 0 ; i < 4 ; i++) |
jksoft | 0:9fcc79b3f00e | 156 | { |
jksoft | 0:9fcc79b3f00e | 157 | _sensor_def[i] /= 12; |
jksoft | 0:9fcc79b3f00e | 158 | } |
jksoft | 0:9fcc79b3f00e | 159 | SetLed(0); |
jksoft | 0:9fcc79b3f00e | 160 | } |
jksoft | 0:9fcc79b3f00e | 161 | |
jksoft | 0:9fcc79b3f00e | 162 | int wallbotLED::GetLinePosition(void) { |
jksoft | 0:9fcc79b3f00e | 163 | int in[4] = { _f_sensor1.read_u16(), |
jksoft | 0:9fcc79b3f00e | 164 | _f_sensor2.read_u16(), |
jksoft | 0:9fcc79b3f00e | 165 | _f_sensor3.read_u16(), |
jksoft | 0:9fcc79b3f00e | 166 | _f_sensor4.read_u16() |
jksoft | 0:9fcc79b3f00e | 167 | }; |
jksoft | 0:9fcc79b3f00e | 168 | int stat = 0; |
jksoft | 0:9fcc79b3f00e | 169 | |
jksoft | 0:9fcc79b3f00e | 170 | // printf("ad[0]:%05d ad[1]:%05d ad[2]:%05d ad[3]:%05d \n\r",in[0],in[1],in[2],in[3]); |
jksoft | 0:9fcc79b3f00e | 171 | |
jksoft | 0:9fcc79b3f00e | 172 | for(int i = 0 ; i < 4 ; i++) |
jksoft | 0:9fcc79b3f00e | 173 | { |
jksoft | 0:9fcc79b3f00e | 174 | if( (in[i] > (_sensor_def[i] + _sensor_gain)) |
jksoft | 0:9fcc79b3f00e | 175 | ||(in[i] < (_sensor_def[i] - _sensor_gain)) ) |
jksoft | 0:9fcc79b3f00e | 176 | { |
jksoft | 0:9fcc79b3f00e | 177 | stat |= 1 << i; |
jksoft | 0:9fcc79b3f00e | 178 | } |
jksoft | 0:9fcc79b3f00e | 179 | } |
jksoft | 0:9fcc79b3f00e | 180 | |
jksoft | 0:9fcc79b3f00e | 181 | return(stat); |
jksoft | 0:9fcc79b3f00e | 182 | } |
jksoft | 0:9fcc79b3f00e | 183 | |
jksoft | 0:9fcc79b3f00e | 184 | |
jksoft | 0:9fcc79b3f00e | 185 | int wallbotLED::GetSw(void) { |
jksoft | 0:9fcc79b3f00e | 186 | return(_sw ^ 0x3); |
jksoft | 0:9fcc79b3f00e | 187 | } |
jksoft | 0:9fcc79b3f00e | 188 | |
jksoft | 0:9fcc79b3f00e | 189 | bool wallbotLED::GetSw1(void) |
jksoft | 0:9fcc79b3f00e | 190 | { |
jksoft | 0:9fcc79b3f00e | 191 | return(bool)(GetSw() & 0x01); |
jksoft | 0:9fcc79b3f00e | 192 | } |
jksoft | 0:9fcc79b3f00e | 193 | |
jksoft | 0:9fcc79b3f00e | 194 | bool wallbotLED::GetSw2(void) |
jksoft | 0:9fcc79b3f00e | 195 | { |
jksoft | 0:9fcc79b3f00e | 196 | return(bool)(GetSw() & 0x02); |
jksoft | 0:9fcc79b3f00e | 197 | } |
jksoft | 0:9fcc79b3f00e | 198 | |
jksoft | 0:9fcc79b3f00e | 199 | bool wallbotLED::GetFloorSensor1() |
jksoft | 0:9fcc79b3f00e | 200 | { |
jksoft | 0:9fcc79b3f00e | 201 | int in = _f_sensor1.read_u16(); |
jksoft | 0:9fcc79b3f00e | 202 | |
jksoft | 0:9fcc79b3f00e | 203 | if( (in > (_sensor_def[0] + _sensor_gain)) |
jksoft | 0:9fcc79b3f00e | 204 | ||(in < (_sensor_def[0] - _sensor_gain)) ) |
jksoft | 0:9fcc79b3f00e | 205 | { |
jksoft | 0:9fcc79b3f00e | 206 | return true; |
jksoft | 0:9fcc79b3f00e | 207 | } |
jksoft | 0:9fcc79b3f00e | 208 | |
jksoft | 0:9fcc79b3f00e | 209 | return false; |
jksoft | 0:9fcc79b3f00e | 210 | } |
jksoft | 0:9fcc79b3f00e | 211 | |
jksoft | 0:9fcc79b3f00e | 212 | bool wallbotLED::GetFloorSensor2() |
jksoft | 0:9fcc79b3f00e | 213 | { |
jksoft | 0:9fcc79b3f00e | 214 | int in = _f_sensor2.read_u16(); |
jksoft | 0:9fcc79b3f00e | 215 | |
jksoft | 0:9fcc79b3f00e | 216 | if( (in > (_sensor_def[1] + _sensor_gain)) |
jksoft | 0:9fcc79b3f00e | 217 | ||(in < (_sensor_def[1] - _sensor_gain)) ) |
jksoft | 0:9fcc79b3f00e | 218 | { |
jksoft | 0:9fcc79b3f00e | 219 | return true; |
jksoft | 0:9fcc79b3f00e | 220 | } |
jksoft | 0:9fcc79b3f00e | 221 | |
jksoft | 0:9fcc79b3f00e | 222 | return false; |
jksoft | 0:9fcc79b3f00e | 223 | } |
jksoft | 0:9fcc79b3f00e | 224 | |
jksoft | 0:9fcc79b3f00e | 225 | bool wallbotLED::GetFloorSensor3() |
jksoft | 0:9fcc79b3f00e | 226 | { |
jksoft | 0:9fcc79b3f00e | 227 | int in = _f_sensor3.read_u16(); |
jksoft | 0:9fcc79b3f00e | 228 | |
jksoft | 0:9fcc79b3f00e | 229 | if( (in > (_sensor_def[2] + _sensor_gain)) |
jksoft | 0:9fcc79b3f00e | 230 | ||(in < (_sensor_def[2] - _sensor_gain)) ) |
jksoft | 0:9fcc79b3f00e | 231 | { |
jksoft | 0:9fcc79b3f00e | 232 | return true; |
jksoft | 0:9fcc79b3f00e | 233 | } |
jksoft | 0:9fcc79b3f00e | 234 | |
jksoft | 0:9fcc79b3f00e | 235 | return false; |
jksoft | 0:9fcc79b3f00e | 236 | } |
jksoft | 0:9fcc79b3f00e | 237 | |
jksoft | 0:9fcc79b3f00e | 238 | bool wallbotLED::GetFloorSensor4() |
jksoft | 0:9fcc79b3f00e | 239 | { |
jksoft | 0:9fcc79b3f00e | 240 | int in = _f_sensor4.read_u16(); |
jksoft | 0:9fcc79b3f00e | 241 | |
jksoft | 0:9fcc79b3f00e | 242 | if( (in > (_sensor_def[3] + _sensor_gain)) |
jksoft | 0:9fcc79b3f00e | 243 | ||(in < (_sensor_def[3] - _sensor_gain)) ) |
jksoft | 0:9fcc79b3f00e | 244 | { |
jksoft | 0:9fcc79b3f00e | 245 | return true; |
jksoft | 0:9fcc79b3f00e | 246 | } |
jksoft | 0:9fcc79b3f00e | 247 | |
jksoft | 0:9fcc79b3f00e | 248 | return false; |
jksoft | 0:9fcc79b3f00e | 249 | } |
jksoft | 0:9fcc79b3f00e | 250 | |
jksoft | 0:9fcc79b3f00e | 251 | uint16_t wallbotLED::GetFloorSensorRaw1() |
jksoft | 0:9fcc79b3f00e | 252 | { |
jksoft | 0:9fcc79b3f00e | 253 | return _f_sensor1.read_u16(); |
jksoft | 0:9fcc79b3f00e | 254 | } |
jksoft | 0:9fcc79b3f00e | 255 | |
jksoft | 0:9fcc79b3f00e | 256 | uint16_t wallbotLED::GetFloorSensorRaw2() |
jksoft | 0:9fcc79b3f00e | 257 | { |
jksoft | 0:9fcc79b3f00e | 258 | return _f_sensor2.read_u16(); |
jksoft | 0:9fcc79b3f00e | 259 | } |
jksoft | 0:9fcc79b3f00e | 260 | |
jksoft | 0:9fcc79b3f00e | 261 | uint16_t wallbotLED::GetFloorSensorRaw3() |
jksoft | 0:9fcc79b3f00e | 262 | { |
jksoft | 0:9fcc79b3f00e | 263 | return _f_sensor3.read_u16(); |
jksoft | 0:9fcc79b3f00e | 264 | } |
jksoft | 0:9fcc79b3f00e | 265 | |
jksoft | 0:9fcc79b3f00e | 266 | uint16_t wallbotLED::GetFloorSensorRaw4() |
jksoft | 0:9fcc79b3f00e | 267 | { |
jksoft | 0:9fcc79b3f00e | 268 | return _f_sensor4.read_u16(); |
jksoft | 0:9fcc79b3f00e | 269 | } |
jksoft | 0:9fcc79b3f00e | 270 | |
jksoft | 0:9fcc79b3f00e | 271 | void wallbotLED::GetAcceleration(float *x,float *y,float *z) |
jksoft | 0:9fcc79b3f00e | 272 | { |
jksoft | 0:9fcc79b3f00e | 273 | int16_t _x,_y,_z; |
jksoft | 0:9fcc79b3f00e | 274 | _mpu.getAcceleration(&_x,&_y,&_z); |
jksoft | 0:9fcc79b3f00e | 275 | |
jksoft | 0:9fcc79b3f00e | 276 | *x = (float)_x / 8192; |
jksoft | 0:9fcc79b3f00e | 277 | *y = (float)_y / 8192; |
jksoft | 0:9fcc79b3f00e | 278 | *z = (float)_z / 8192; |
jksoft | 0:9fcc79b3f00e | 279 | } |
jksoft | 0:9fcc79b3f00e | 280 | |
jksoft | 0:9fcc79b3f00e | 281 | float wallbotLED::GetAccelerationX() |
jksoft | 0:9fcc79b3f00e | 282 | { |
jksoft | 0:9fcc79b3f00e | 283 | return (float)_mpu.getAccelerationX() / 8192; |
jksoft | 0:9fcc79b3f00e | 284 | } |
jksoft | 0:9fcc79b3f00e | 285 | |
jksoft | 0:9fcc79b3f00e | 286 | float wallbotLED::GetAccelerationY() |
jksoft | 0:9fcc79b3f00e | 287 | { |
jksoft | 0:9fcc79b3f00e | 288 | return (float)_mpu.getAccelerationY() / 8192; |
jksoft | 0:9fcc79b3f00e | 289 | } |
jksoft | 0:9fcc79b3f00e | 290 | |
jksoft | 0:9fcc79b3f00e | 291 | float wallbotLED::GetAccelerationZ() |
jksoft | 0:9fcc79b3f00e | 292 | { |
jksoft | 0:9fcc79b3f00e | 293 | return (float)_mpu.getAccelerationZ() / 8192; |
jksoft | 0:9fcc79b3f00e | 294 | } |
jksoft | 0:9fcc79b3f00e | 295 | |
jksoft | 0:9fcc79b3f00e | 296 | void wallbotLED::GetGyro(float *x,float *y,float *z) |
jksoft | 0:9fcc79b3f00e | 297 | { |
jksoft | 0:9fcc79b3f00e | 298 | int16_t _x,_y,_z; |
jksoft | 0:9fcc79b3f00e | 299 | _mpu.getRotation(&_x,&_y,&_z); |
jksoft | 0:9fcc79b3f00e | 300 | |
jksoft | 0:9fcc79b3f00e | 301 | *x = (float)_x / 131; |
jksoft | 0:9fcc79b3f00e | 302 | *y = (float)_y / 131; |
jksoft | 0:9fcc79b3f00e | 303 | *z = (float)_z / 131; |
jksoft | 0:9fcc79b3f00e | 304 | } |
jksoft | 0:9fcc79b3f00e | 305 | |
jksoft | 0:9fcc79b3f00e | 306 | float wallbotLED::GetGyroX() |
jksoft | 0:9fcc79b3f00e | 307 | { |
jksoft | 0:9fcc79b3f00e | 308 | return (float)_mpu.getAccelerationX() / 131; |
jksoft | 0:9fcc79b3f00e | 309 | } |
jksoft | 0:9fcc79b3f00e | 310 | |
jksoft | 0:9fcc79b3f00e | 311 | float wallbotLED::GetGyroY() |
jksoft | 0:9fcc79b3f00e | 312 | { |
jksoft | 0:9fcc79b3f00e | 313 | return (float)_mpu.getAccelerationY() / 131; |
jksoft | 0:9fcc79b3f00e | 314 | } |
jksoft | 0:9fcc79b3f00e | 315 | |
jksoft | 0:9fcc79b3f00e | 316 | float wallbotLED::GetGyroZ() |
jksoft | 0:9fcc79b3f00e | 317 | { |
jksoft | 0:9fcc79b3f00e | 318 | return (float)_mpu.getAccelerationZ() / 131; |
jksoft | 0:9fcc79b3f00e | 319 | } |
jksoft | 0:9fcc79b3f00e | 320 | |
jksoft | 0:9fcc79b3f00e | 321 | void wallbotLED::SetLedPanel(char data[][16]) |
jksoft | 0:9fcc79b3f00e | 322 | { |
jksoft | 0:9fcc79b3f00e | 323 | for (int y = 0; y < 8; y++) { |
jksoft | 0:9fcc79b3f00e | 324 | for (int x = 0; x < 16; x++) { |
jksoft | 0:9fcc79b3f00e | 325 | if( data[x][y+8] == 1 ) |
jksoft | 0:9fcc79b3f00e | 326 | { |
jksoft | 0:9fcc79b3f00e | 327 | _matrix1.drawPixel(x, y, LED_ON); |
jksoft | 0:9fcc79b3f00e | 328 | } |
jksoft | 0:9fcc79b3f00e | 329 | else |
jksoft | 0:9fcc79b3f00e | 330 | { |
jksoft | 0:9fcc79b3f00e | 331 | _matrix1.drawPixel(x, y, LED_OFF); |
jksoft | 0:9fcc79b3f00e | 332 | } |
jksoft | 0:9fcc79b3f00e | 333 | if( data[x][y] == 1 ) |
jksoft | 0:9fcc79b3f00e | 334 | { |
jksoft | 0:9fcc79b3f00e | 335 | _matrix2.drawPixel(x, y, LED_ON); |
jksoft | 0:9fcc79b3f00e | 336 | } |
jksoft | 0:9fcc79b3f00e | 337 | else |
jksoft | 0:9fcc79b3f00e | 338 | { |
jksoft | 0:9fcc79b3f00e | 339 | _matrix2.drawPixel(x, y, LED_OFF); |
jksoft | 0:9fcc79b3f00e | 340 | } |
jksoft | 0:9fcc79b3f00e | 341 | } |
jksoft | 0:9fcc79b3f00e | 342 | } |
jksoft | 0:9fcc79b3f00e | 343 | _matrix1.writeDisplay(); |
jksoft | 0:9fcc79b3f00e | 344 | _matrix2.writeDisplay(); |
jksoft | 0:9fcc79b3f00e | 345 | } |
jksoft | 0:9fcc79b3f00e | 346 | |
jksoft | 0:9fcc79b3f00e | 347 | void wallbotLED::SetLedPanel(int x, int y, int flag) |
jksoft | 0:9fcc79b3f00e | 348 | { |
jksoft | 0:9fcc79b3f00e | 349 | if(y < 8) { |
jksoft | 0:9fcc79b3f00e | 350 | _matrix1.drawPixel(x, y, flag); |
jksoft | 0:9fcc79b3f00e | 351 | _matrix1.writeDisplay(); |
jksoft | 0:9fcc79b3f00e | 352 | } |
jksoft | 0:9fcc79b3f00e | 353 | else { |
jksoft | 0:9fcc79b3f00e | 354 | _matrix2.drawPixel(x, y-8, flag); |
jksoft | 0:9fcc79b3f00e | 355 | _matrix2.writeDisplay(); |
jksoft | 0:9fcc79b3f00e | 356 | } |
jksoft | 0:9fcc79b3f00e | 357 | } |
jksoft | 0:9fcc79b3f00e | 358 |