loading

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.

Step 1: 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.

Step 2: 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();
        }
    }
}

Step 3:

About This Instructable

1,171views

5favorites

More by kubavit:STM32F4 Discovery part2 - ADC Graph STM32F4 Discovery part1 - Touch Buttons Getting started with FRDM kl46z part 4 - ADC & DAC 
Add instructable to: