1. Home
  2. /
  3. Mbed-cpp Typing Test
  4. /
  5. Mbed C++ Button Press Counter

Mbed C++ Button Press Counter - Mbed-cpp Typing CST Test

Skip to main content
CodeSpeedTest
Languages
Start TypingJump into a test — pick any languageAdaptive TrainingUnlock chars as you master themPractice DrillsFocused sessions targeting weak spotsDaily ChallengesNew coding challenges every dayRace ModeCompete against others in real timeAI OpponentRace against an AI at your WPM levelTournamentsLive coding speed tournamentsArcade GamesZType, Overkill Survival, Glyphica & moreGamificationXP, coins, badges & quests
LeaderboardGlobal rankings for every languageCertificatesEarn verifiable Bronze / Silver / Gold certsActivityDaily streaks & historical analyticsProfileYour stats, badges & achievements
Browse Languages500+ languages with real code examplesBlogTips, guides & deep divesFree ToolsWPM calculator, typing speed report & moreFAQCommon questions answeredGetting StartedNew to CodeSpeedTest?AboutOur story & missionSupportGet help — Pro users get priorityContactGet in touch with the team
Pricing
Mode:
Duration:
1
Coding works best on desktop or with an external keyboard.
CodeSpeedTest

Improve your coding speed, code accuracy, and programming syntax WPM with practice sessions across 500+ programming languages.

Quick Links

HomeAboutFeaturesGetting StartedLanguages

Legal & Support

Pro ⚡ PricingContactPrivacy PolicyTerms of Service

Connect

CodeSpeedTest on GitHubCodeSpeedTest on TwitterEmail CodeSpeedTest

© 2026 CodeSpeedTest. All rights reserved.

Mbed C++ Button Press Counter — Mbed-cpp Code

Counts button presses and toggles an LED on each press.

#include "mbed.h"

DigitalOut led(LED1);
InterruptIn button(USER_BUTTON);
int buttonCount = 0;

void updateUI() {
	printf("Button Count: %d\n", buttonCount);
	led = buttonCount % 2;
}

void buttonPressed() {
	buttonCount++;
	updateUI();
}

int main() {
	button.rise(&buttonPressed);
	updateUI();
	while(1) {}
}

Mbed-cpp Language Guide

Mbed OS (mbed-cpp) is an open-source embedded operating system and C++ framework designed for ARM Cortex-M microcontrollers. It provides a full-featured platform for building IoT devices, supporting real-time operating system capabilities, peripheral access, and connectivity.

Primary Use Cases

  • ▸Professional IoT and embedded device development
  • ▸Real-time applications with RTOS support
  • ▸Networking and connected devices (Wi-Fi, BLE, LoRa, Ethernet)
  • ▸Sensor and actuator control for robotics and automation
  • ▸Prototyping and production-level embedded systems

Notable Features

  • ▸RTOS with multi-threading, timers, and events
  • ▸Hardware abstraction layer for peripherals
  • ▸Connectivity stacks for Wi-Fi, BLE, Ethernet, LoRa, and cellular
  • ▸Power management and low-power modes
  • ▸Extensive C++ library ecosystem for embedded development

Origin & Creator

Developed by ARM Ltd. in 2009 to create a unified C++ platform for ARM Cortex-M microcontrollers and IoT devices.

Industrial Note

Mbed OS is widely used in industrial IoT, connected devices, wearable electronics, and embedded prototyping where professional-grade C++ performance and RTOS features are required.

Quick Explain

  • ▸Mbed OS enables developers to write C++ code for microcontrollers with access to RTOS features, drivers, and middleware.
  • ▸It provides abstractions for hardware peripherals, sensors, communication protocols, and networking stacks.
  • ▸Ideal for professional embedded development, IoT devices, and performance-critical applications.

Core Features

  • ▸Runs on ARM Cortex-M microcontrollers
  • ▸Preemptive RTOS with threads and mutexes
  • ▸Filesystem support for onboard storage
  • ▸Peripheral drivers for GPIO, ADC, PWM, UART, I2C, SPI
  • ▸Networking and IoT protocols integrated

Learning Path

  • ▸Learn C++ basics
  • ▸Understand microcontroller architecture and GPIO
  • ▸Learn RTOS concepts: threads, events, timers
  • ▸Install Mbed Studio or CLI
  • ▸Build simple embedded and IoT applications

Practical Examples

  • ▸Blinking LEDs with threads
  • ▸Reading sensors via I2C/SPI
  • ▸Controlling motors with PWM
  • ▸Wi-Fi/BLE communication for IoT
  • ▸Low-power sleep and wake-up routines

Comparisons

  • ▸Mbed C++ is lower-level than MicroPython/CircuitPython
  • ▸Better suited for professional-grade embedded applications
  • ▸RTOS support and multi-threading not available in Python-based variants
  • ▸Higher memory footprint but more performance
  • ▸Production-ready with advanced connectivity and security

Strengths

  • ▸High-performance C++ environment
  • ▸Robust RTOS and multi-threading support
  • ▸Wide hardware and connectivity support
  • ▸Production-grade embedded system features
  • ▸Strong ecosystem with professional libraries and tools

Limitations

  • ▸Requires C++ knowledge and embedded experience
  • ▸Larger memory footprint than lightweight scripting languages
  • ▸Steeper learning curve for beginners
  • ▸Complexity increases for small-scale hobby projects
  • ▸Less interactive than Python-based embedded scripting

When NOT to Use

  • ▸Simple hobby projects with minimal code
  • ▸Rapid prototyping for beginners without C++ experience
  • ▸Memory-constrained microcontrollers without RTOS support
  • ▸Projects needing interactive scripting
  • ▸Quick educational projects requiring Python simplicity

Cheat Sheet

  • ▸#include 'mbed.h'
  • ▸DigitalOut led(LED1); led = 1;
  • ▸AnalogIn sensor(A0); float value = sensor.read();
  • ▸Thread thread(osPriorityNormal, 1024); thread.start(callback(fn));
  • ▸NetworkInterface *net = NetworkInterface::get_default_instance(); net->connect();

FAQ

  • ▸Is Mbed OS beginner-friendly?
  • ▸Moderate learning curve; some C++ and embedded knowledge required.
  • ▸Which boards support Mbed OS?
  • ▸ARM Cortex-M based boards (STM32, NXP, Nordic, etc.)
  • ▸Does it support Python scripting?
  • ▸No, C++ is primary language for Mbed OS.
  • ▸Can it be used for IoT devices?
  • ▸Yes, it includes Wi-Fi, BLE, LoRa, and Ethernet stacks.
  • ▸Is Mbed OS suitable for commercial embedded products?
  • ▸Yes, it is production-ready and widely used in industry.

30-Day Skill Plan

  • ▸Week 1: C++ syntax and microcontroller basics
  • ▸Week 2: GPIO, PWM, ADC, I2C, SPI practice
  • ▸Week 3: Threading and RTOS event handling
  • ▸Week 4: Networking (Wi-Fi/BLE) integration
  • ▸Week 5: Complete IoT or automation projects

Final Summary

  • ▸Mbed OS is a professional C++ platform for ARM Cortex-M microcontrollers.
  • ▸Supports RTOS, networking, peripherals, and IoT protocols.
  • ▸Suitable for performance-critical and production-grade embedded devices.
  • ▸Offers rich ecosystem, tools, and libraries for professional development.
  • ▸Focuses on high performance, scalability, and security in embedded applications.

Project Structure

  • ▸main.cpp - entry point of application
  • ▸mbed_app.json - configuration file
  • ▸drivers/ - peripheral drivers
  • ▸rtos/ - threads and event handling
  • ▸lib/ - additional libraries and modules

Monetization

  • ▸Commercial embedded systems
  • ▸IoT devices and solutions
  • ▸Professional robotics and automation products
  • ▸Industrial sensor networks
  • ▸Prototyping and production-ready electronics

Productivity Tips

  • ▸Use RTOS and event queues to organize code
  • ▸Keep code modular and maintainable
  • ▸Test each peripheral before combining tasks
  • ▸Use IDE and CLI tools effectively
  • ▸Regularly update Mbed OS and libraries

Basic Concepts

  • ▸Thread and RTOS task management
  • ▸Digital and analog I/O
  • ▸Timers, interrupts, and event queues
  • ▸Peripheral drivers and abstraction layers
  • ▸Networking protocols (MQTT, HTTP, BLE, LoRa, Ethernet)

Official Docs

  • ▸Mbed OS Documentation
  • ▸Mbed OS API Reference
  • ▸Mbed CLI and Studio Guides
  • ▸ARM Developer Community for Mbed
  • ▸Mbed OS GitHub repositories

More Mbed-cpp Typing Exercises

Mbed C++ LED BlinkMbed C++ Temperature MonitorMbed C++ PWM LED BrightnessMbed C++ Relay ToggleMbed C++ Buzzer ToggleMbed C++ Fan Speed ControlMbed C++ Dual LED ToggleMbed C++ Humidity AlertMbed C++ LED Blink Pattern

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher