From 01d2e8eb08066a21faeb30767f3408d8526da2e5 Mon Sep 17 00:00:00 2001 From: ddebernardde <diego.debernard@student.uclouvain.be> Date: Wed, 9 Nov 2022 01:34:45 +0100 Subject: [PATCH] code led I2C ok --- I2C.cpp | 34 ++++++++++++++++++++++++++++++++++ Makefile | 8 ++++++-- encoder.c | 4 ++-- 3 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 I2C.cpp diff --git a/I2C.cpp b/I2C.cpp new file mode 100644 index 0000000..01a2603 --- /dev/null +++ b/I2C.cpp @@ -0,0 +1,34 @@ +#include <stdio.h> +#include <stdlib.h> + +#include <wiringPiI2C.h> +#include <wiringPi.h> + +#include <iostream> + +using namespace std; + +const int LED = 0x08; +const int ON = 0x01; +const int OFF = 0x00; + +int main(int argc, char const *argv[]) { + + int fd = wiringPiI2CSetup(LED); + + wiringPiI2CWrite(fd, ON); + + if (wiringPiI2CRead(fd) == ON) { + printf("LIGHT ON!\n"); + } + + delay(5000); + + wiringPiI2CWrite(fd, OFF); + + if (wiringPiI2CRead(fd) == OFF) { + printf("LIGHT OFF!\n"); + } + + return 0; +} diff --git a/Makefile b/Makefile index 3183546..22a4528 100644 --- a/Makefile +++ b/Makefile @@ -6,6 +6,9 @@ switch : compile_switch motor : compile_motor sudo ./motor +led : compile_LED + sudo ./led + # compilations compile_switch : @@ -14,8 +17,9 @@ compile_switch : compile_motor : gcc -o motor motor.c -lwiringPi +compile_LED : + g++ -o led I2C.cpp -lwiringPi .PHONY : clean clean : - rm -rf switch - rm -rf motor \ No newline at end of file + rm -rf switch motor led diff --git a/encoder.c b/encoder.c index 89ddfe3..b7977b2 100644 --- a/encoder.c +++ b/encoder.c @@ -14,8 +14,8 @@ const int ENC_PIN_2A = 35; //from FPGA to ENCODER -> ouput data from encod const int ENC_PIN_2B = 34; //from FPGA to ENCODER -> ouput data from encoder const int SCK_PIN = 14; //from RASPI to FPGA -> clock signal const int SCK_PIN_FPGA = 13; //from FPGA to ENCODER -> clock signal -const int SS_BAR_1 = 2; //from RASPI to FPGA -> enable encoder -const int SS_BAR_2 = 3; //from RASPI to FPGA -> enable encoder +const int SS_BAR_1 = 10; //CE0 from RASPI to FPGA -> enable encoder +const int SS_BAR_2 = 11; //CE1 from RASPI to FPGA -> enable encoder int main(int argc, char const *argv[]) { -- GitLab