implementation of simple class for raspberry pi pwm blink program (Embedded Programming)

Pages: 12
If'n you want to learn what C++ experts consider core guidelines for writing good C++ code you should read this:

https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines

The introduction explains what's going on.

https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#S-introduction
I suggest that Windows programmers who want to catch Ctrl-C should strongly prefer to call SetConsoleCtrlHandler instead


If all you want to do is to terminate a loop with ctrl-c (or any other char) and continue, then you don't need to install a handler. You do something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <conio.h>
#include <iostream>

int main() {
	SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), 0);

	while (!_kbhit() || _getch() != 3)
		_putch('a');

	std::cout << "\nctrl-c\n";
}

@George P:

Thank you so much for the encouragement, for the links provided (for core guidelines, and so on) and for the valuable suggestions offered including the one on using directives.

I plan to revert to these resources as I make progress.


@seeplus:

Wow, I'm speechless! Never knew this was possible : )

Thank you for sharing this.

I would keep you guys posted when other ideas and challenges come to mind while I continue work on this personal project.

Much regards.
Last edited on
What is the OS on your Raspberry Pi, if any? According to Wikipedia it can utilize quite a variety. The default is a *nix variation created for the board, with a zero-price version of Windows 10 IoT Core available for a Pi 2.

https://en.wikipedia.org/wiki/Raspberry_Pi#Operating_systems

Thank you for sharing this. By the way, the OS on my RPi is:

$ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 11 (bullseye)"
NAME="Raspbian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"

A couple of things to note, coming from someone who is a still-learning self-taught programming hobbyist who doesn't use Linux.....

1. Using Windows headers (conio.h) and WinAPI functions in program code that runs on a *nix variation is fraught with "dragons be here" peril.

2. I suspect the RPi OS is some form of a stripped down *nix, there is probably some C/C++ functionality that doesn't exist.

Back to your regularly scheduled programming channel....
Registered users can post here. Sign in or register to post.
Pages: 12