Review Exploring the Raspberry Pi 2 with C++

Exploring the Raspberry Pi 2 with C++

[Số Lượng Có Hạn - Đừng Chần Chừ, Mua Ngay Thôi!]: (https://shorten.asia/tD2CsfeK)
** Khám phá Raspberry Pi 2 với C ++ **

Raspberry Pi là một máy tính một bảng phổ biến, hoàn hảo để học lập trình và thiết bị điện tử.Trong bài viết này, chúng tôi sẽ khám phá Raspberry Pi 2 với C ++.Chúng tôi sẽ bao gồm những điều cơ bản của lập trình C ++, cũng như cách sử dụng các chân GPIO Raspberry Pi.

## Bắt đầu với C ++ trên Raspberry Pi

Điều đầu tiên chúng ta cần làm là cài đặt trình biên dịch C ++ trên Raspberry Pi.Chúng ta có thể làm điều này bằng cách chạy lệnh sau:

`` `
sudo apt-get cài đặt gcc-arm-linux-gnueabihf
`` `

Khi trình biên dịch được cài đặt, chúng tôi có thể tạo một dự án C ++ mới.Chúng ta có thể làm điều này bằng cách tạo một thư mục mới và mở trình soạn thảo văn bản.Trong trình soạn thảo văn bản, chúng tôi có thể nhập mã sau:

`` `C ++
#include <Istream>

int main () {
std :: cout << "Xin chào, thế giới!"<< std :: endl;

trả lại 0;
}
`` `

Chúng ta có thể lưu tệp này dưới dạng `hello_world.cpp`.Để biên dịch chương trình, chúng tôi có thể chạy lệnh sau:

`` `
sudo gcc -o hello_world hello_world.cpp
`` `

Điều này sẽ tạo một tệp thực thi có tên là `hello_world`.Chúng tôi có thể chạy chương trình bằng cách chạy lệnh sau:

`` `
./Chào thế giới
`` `

Điều này sẽ in tin nhắn "Xin chào, Thế giới!"đến giao diện điều khiển.

## Sử dụng các chân GPIO Raspberry Pi

Raspberry Pi có một số chân GPIO có thể được sử dụng để điều khiển các thiết bị điện tử.Để sử dụng các chân GPIO, chúng ta cần nhập thư viện `WiresPi`.Chúng ta có thể làm điều này bằng cách chạy lệnh sau:

`` `
sudo apt-get install wirespi
`` `

Sau khi thư viện được cài đặt, chúng tôi có thể sử dụng mã sau để đặt giá trị của chân GPIO:

`` `C ++
#include <wirespi.h>

int main () {
// Đặt chế độ của pin GPIO 17 thành đầu ra.
Pinmode (17, đầu ra);

// Đặt giá trị của chân GPIO 17 thành cao.
DigitalWrite (17, cao);

trả lại 0;
}
`` `

Để chạy chương trình này, chúng tôi có thể sử dụng lệnh sau:

`` `
sudo gcc -o led_blink led_blink.cpp -lwirespi
./led_blink
`` `

Điều này sẽ nhấp nháy đèn LED được kết nối với chân GPIO 17.

## Phần kết luận

Trong bài viết này, chúng tôi đã khám phá Raspberry Pi 2 với C ++.Chúng tôi đã đề cập đến những điều cơ bản của lập trình C ++, cũng như cách sử dụng các chân GPIO Raspberry Pi.Để biết thêm thông tin về Raspberry Pi, vui lòng truy cập [Trang web Raspberry Pi] (Teach, learn, and make with the Raspberry Pi Foundation).

### hashtags

* #raspberrypi
* #C ++
* #Programming
=======================================
[Số Lượng Có Hạn - Đừng Chần Chừ, Mua Ngay Thôi!]: (https://shorten.asia/tD2CsfeK)
=======================================
**Exploring the Raspberry Pi 2 with C++**

The Raspberry Pi is a popular single-board computer that is perfect for learning programming and electronics. In this article, we will explore the Raspberry Pi 2 with C++. We will cover the basics of C++ programming, as well as how to use the Raspberry Pi GPIO pins.

## Getting Started with C++ on the Raspberry Pi

The first thing we need to do is install the C++ compiler on the Raspberry Pi. We can do this by running the following command:

```
sudo apt-get install gcc-arm-linux-gnueabihf
```

Once the compiler is installed, we can create a new C++ project. We can do this by creating a new directory and opening a text editor. In the text editor, we can type the following code:

```c++
#include <iostream>

int main() {
std::cout << "Hello, world!" << std::endl;

return 0;
}
```

We can save this file as `hello_world.cpp`. To compile the program, we can run the following command:

```
sudo gcc -o hello_world hello_world.cpp
```

This will create an executable file called `hello_world`. We can run the program by running the following command:

```
./hello_world
```

This will print the message "Hello, world!" to the console.

## Using the Raspberry Pi GPIO Pins

The Raspberry Pi has a number of GPIO pins that can be used to control electronic devices. To use the GPIO pins, we need to import the `wiringPi` library. We can do this by running the following command:

```
sudo apt-get install wiringpi
```

Once the library is installed, we can use the following code to set the value of a GPIO pin:

```c++
#include <wiringPi.h>

int main() {
// Set the mode of GPIO pin 17 to output.
pinMode(17, OUTPUT);

// Set the value of GPIO pin 17 to high.
digitalWrite(17, HIGH);

return 0;
}
```

To run this program, we can use the following command:

```
sudo gcc -o led_blink led_blink.cpp -lwiringPi
./led_blink
```

This will blink the LED connected to GPIO pin 17.

## Conclusion

In this article, we explored the Raspberry Pi 2 with C++. We covered the basics of C++ programming, as well as how to use the Raspberry Pi GPIO pins. For more information on the Raspberry Pi, please visit the [Raspberry Pi website](https://www.raspberrypi.org/).

### Hashtags

* #raspberrypi
* #C++
* #Programming
=======================================
[Sản Phẩm Dành Riêng Cho Bạn - Mua Ngay!]: (https://shorten.asia/tD2CsfeK)
 
Join Telegram ToolsKiemTrieuDoGroup
Back
Top