# icepi.raspberry-pi **Repository Path**: dhclly/icepi.raspberry-pi ## Basic Information - **Project Name**: icepi.raspberry-pi - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2019-11-23 - **Last Updated**: 2024-11-29 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Raspberry Pi 4B 对于做的实验的一个记录 ## 快捷执行命令脚本 c.sh ```bash # desc:compile link run # author:dhclly # time 2019/11/21 echo 'gcc version:gcc version 8.3.0 (Raspbian 8.3.0-6+rpi1)' echo =====execute start===== gcc $1 -o $1.out -l wiringPi -l pthread && ./$1.out echo =====execute end===== ``` cpp.sh ```bash # desc:compile link run # author:dhclly # time 2019/11/21 echo 'gcc version:gcc version 8.3.0 (Raspbian 8.3.0-6+rpi1)' echo =====execute start===== g++ $1 -o $1.out -l wiringPi -l pthread && ./$1.out echo =====execute end===== ``` py2.sh ```bash # python 2 shutcut execute script # author:dhclly echo python version: python2 -V echo =====execute start===== python2 $1 echo =====execute end===== ``` py3.sh ```bash # python 3 shutcut execute script # author:dhclly echo python version: python3 -V echo =====execute start===== python3 $1 echo =====execute end===== ``` ## c/c++编译执行指令 ```bash # c gcc $1 -o $1.out -l wiringPi -l pthread && ./$1.out # c++ g++ $1 -o $1.out -l wiringPi -l pthread && ./$1.out # c++ 也可以使用下面的语句 gcc $1 -o $1.out -l wiringPi -l pthread -l stdc++ && ./$1.out ``` 注: - -l 参数是指定程序要链接的库 - wiringPi 库是硬件针脚操作库 - pthread 库是一个多线程库 - stdc++库是c++标准库 ### hello-world.c ```c #include int main(void) { printf("hello world\n"); return 0; } ``` ### hello-world.cpp ```c++ #include using namespace std; int main() { cout << "hello world\n"; return 0; } ``` ## python 执行指令 ``` python code.py ``` ### hello-world.py ```python print "hello world" #2 print("hello world");#3 ``` ## 实验列表 - 01 双色led灯实验 - 02 RGB三色LED灯实验 - 03 继电器实验 - 04 镭射激光实验 - 05 轻触开关实验 - 06 倾斜开关实验 - 07 震动开关实验 - 08 有源蜂鸣器实验 - 09 无源蜂鸣器实验 ## 风扇的接线方式 风扇安装在壳子外面 | | 风扇红色线 | 风扇黑色线 | | ----------------- | ---------- | ---------- | | 板子上的针脚 | 针脚4 | 针脚6 | | T型转接板上的针脚 | 5V | GND | ## c/c++代码中遇到的问题 ### warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings] warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings] - 神様のいない日々 - CSDN博客 https://blog.csdn.net/VVVLeHr/article/details/86697346 warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings] - zkfopen - 博客园 https://www.cnblogs.com/zkfopen/p/10521715.html 在C++11中有明确规定 ```c++ char* p = "abc"; // valid in C, invalid in C++ ``` 如果你进行了这样的赋值,那么编译器就会跳出诸如标题的警告。但是如果你改成下面这样就会通过warning ```c++ char* p = (char*)"abc"; //OK ``` 或者这样: ```c++ char const *p="abc";//OK ``` 这到底是怎么一回事呢?事实上,我们在学习c或者c++的时候都知道,如果在赋值操作的时候,等号两边的变量类型不一样,那么编译器会进行一种叫做 `implicit conversion` 的操作来使得变量可以被赋值。 在我们上面的表达式中就存在这样的一个问题,等号右边的`"abc"`是一个不变常量,在c++中叫做`string literal`,`type`是`const char *`,而`p`则是一个`char`指针。如果强行赋值会发生什么呢?没错,就是将右边的常量强制类型转换成一个指针,结果就是我们在修改一个`const`常量。编译运行的结果会因编译器和操作系统共同决定,有的编译器会通过,有的会抛异常,就算过了也可能因为操作系统的敏感性而被杀掉。 像这种直接将`string literal `赋值给指针的操作被开发者们认为是`deprecated`,只不过由于以前很多代码都有这种习惯,为了兼容,就保留下来了。