Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Firmware/project_1/inc/pins.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#define P_LED2 P0_5
#define P_LED3 P0_6
#define P_LED4 P0_7
#define P_LED P0_4
#define P_POT A0
// PROJECT 1 - You can define a pin macro here

/*
Expand All @@ -35,15 +37,15 @@ extern DigitalOut led1;
extern DigitalOut led2;
extern DigitalOut led3;
extern DigitalOut led4;
// PROJECT 1 - You can declare a DigitalOut object here

// PROJECT 1 - You can declare a DigitalOut object here
extern DigitalOut test_led;
/*
* BOARD SPECIFIC PINS
*/

// PROJECT 2 - You can declare a AnalogIn object here


extern AnalogIn pot;
/*
* BOARD SPECIFIC PIN OBJECT DECLARATIONS
*/
Expand Down
2 changes: 1 addition & 1 deletion Firmware/project_1/inc/setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

//task 1 rate
// PROJECT 1 - You can change the macro name to something more descriptive if you'd like
#define TASK_1_RATE_US 1000000
#define BLINK_RATE 1000000



Expand Down
15 changes: 12 additions & 3 deletions Firmware/project_1/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@

#include <mbed.h>
// PROJECT 1 - Include something here!
#include "pins.h"
#include "setup.h"
#include "peripherals.h"
#include "can_struct.h"
#include "CAN/can_id.h"
#include "CAN/can_data.h"
#include "can_buffer.h"



/*
* This is an example function. It blinks the heartbeat LED and sends
* a Heartbeat CAN Message. The message sends when the LED turns on.
Expand All @@ -37,7 +40,7 @@ void checkCANController() {
* be a good place to do it.
*/
void setup() {

// yes this works
//set up the CAN interrupts and handling.
common.setupCAN();
//set up LEDs and turn them all off
Expand Down Expand Up @@ -81,10 +84,11 @@ int main() {
bool shutdown = false;
// Main functionality
while (!shutdown) {

//on time overflow all callbacks will happen and timing reset to 0. Might be needed for other functions that rely on timing.
bool overflow;
uint32_t now = common.loopTime(&timing, &overflow);


//clear CAN Buffer
while(!common.readCANMessage(msg)) {
Expand All @@ -94,9 +98,14 @@ int main() {
//total messages. Do nothing for irrelevant messages
common.toggleReceiveCANLED();
}
// project 2
float pot_val = pot.read();
uint32_t blink = pot_val * BLINK_RATE;


if(timing.tickThreshold(last_task_1_time, TASK_1_RATE_US)){
if(timing.tickThreshold(last_task_1_time, BLINK_RATE)){
//PROJECT 1 - add code here to actually make the LED blink
test_led = !test_led;
}

//PROJECT 2 - use the potentiometer to change the blink rate
Expand Down
4 changes: 3 additions & 1 deletion Firmware/project_1/src/pins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/

// PROJECT 2 - You can instantiate your AnalogIn object here

AnalogIn pot(P_POT);
/*
* COMMON PIN OBJECT INSTANTIATIONS
*/
Expand All @@ -22,4 +22,6 @@ DigitalOut led1(P_LED1);
DigitalOut led2(P_LED2);
DigitalOut led3(P_LED3);
DigitalOut led4(P_LED4);

// PROJECT 1 - You can instantiate your DigitalOut object here
DigitalOut test_led(P_LED);
Loading