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.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

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:

Be the First to Share

    Recommendations

    • Made with Math Contest

      Made with Math Contest
    • Multi-Discipline Contest

      Multi-Discipline Contest
    • Robotics Contest

      Robotics Contest

    Discussions