Getting Started With FRDM Kl46z Part 1 - LEDs & Switches
by kubavit in Circuits > Microcontrollers
3140 Views, 5 Favorites, 0 Comments
Getting Started With FRDM Kl46z Part 1 - LEDs & Switches
I want to show you few simple projects using kinetis frdm kl46z and mbed.org compiler. It's very fast and easy to write a programme with it.
Firstly I'll show you how to use microswitch to toggle leds with timer.
Prepare Your Microcontroler
To get start with mbed.org go on side https://developer.mbed.org/ and create free account. There are also instructions how to prepare kl46z board. If you are ready open compiler and create first project.
Writing a Programme
As You can see below we have to include Timer.h and set LEDs as digital output & switches as digital input. Then create object timer to introduce delay between toggling leds. The while loop is very simple. If switch is low state, start the timer and toggle led. At the end reset timer. Thats all !
#include "mbed.h"<br>#include <Timer.h>
DigitalOut greenLed(LED1); DigitalOut redLed(LED2); DigitalIn sw1(SW1); DigitalIn sw3(SW3); Timer timer;
int main(void) { while(1) { if(sw3 == 0) { timer.start(); if(timer.read_ms() == 200) { greenLed = !greenLed; timer.reset(); } } if(sw1 == 0) { timer.start(); if(timer.read_ms() == 20) { redLed = !redLed; timer.reset(); } } timer.stop(); if(timer.read_ms() > 200) { timer.reset(); } } }