Last active
September 7, 2023 15:32
-
-
Save takanotaiga/d46d1559758c67b22c6927ddde165d64 to your computer and use it in GitHub Desktop.
mbed with gm6020
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright (c) 2017-2020 Arm Limited and affiliates. | |
* SPDX-License-Identifier: Apache-2.0 | |
*/ | |
#include "InterfaceCAN.h" | |
#include "PinNames.h" | |
#include <cstdint> | |
#if !DEVICE_CAN | |
#error [NOT_SUPPORTED] CAN not supported for this target | |
#endif | |
#include "mbed.h" | |
/** The constructor takes in RX, and TX pin respectively. | |
* These pins, for this example, are defined in mbed_app.json | |
*/ | |
CAN can(PB_8, PB_9, 1000 * 1000); | |
int16_t power = 0; | |
bool flag; | |
int main() | |
{ | |
printf("main()\n"); | |
CANMessage msg; | |
while (1) { | |
auto msg = CANMessage(); | |
msg.id = 0x1ff; | |
msg.len = 8; | |
msg.data[0] = power >> 8 & 0xff; | |
msg.data[1] = power & 0xff; | |
msg.data[2] = 0; | |
msg.data[3] = 0; | |
msg.data[4] = 0; | |
msg.data[5] = 0; | |
msg.data[6] = 0; | |
msg.data[7] = 0; | |
can.write(msg); | |
ThisThread::sleep_for(100ms); | |
if(flag){ | |
power -= 1000; | |
}else{ | |
power += 1000; | |
} | |
if(power > 30000){ | |
flag = true; | |
} | |
if(power < 500){ | |
flag = false; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment