Skip to content
Extraits de code Groupes Projets
Valider 8cb00734 rédigé par Diego de Bernard de Fauconval's avatar Diego de Bernard de Fauconval
Parcourir les fichiers

bon avancement

parent 01d2e8eb
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -8,11 +8,21 @@ ...@@ -8,11 +8,21 @@
using namespace std; using namespace std;
void takeARide(int speed);
void StopTheRide();
const int LED = 0x08; const int LED = 0x08;
const int ON = 0x01; const int ON = 0x01;
const int OFF = 0x00; const int OFF = 0x00;
int main(int argc, char const *argv[]) { const int ADC = 0x48;
const int PWM_PIN_RIGHT = 23;
const int M1DIR_RIGHT = 21;
const int PWM_PIN_LEFT = 26;
const int M2DIR_LEFT = 22;
void useTheLED() {
int fd = wiringPiI2CSetup(LED); int fd = wiringPiI2CSetup(LED);
...@@ -22,13 +32,81 @@ int main(int argc, char const *argv[]) { ...@@ -22,13 +32,81 @@ int main(int argc, char const *argv[]) {
printf("LIGHT ON!\n"); printf("LIGHT ON!\n");
} }
delay(5000); for (int i = 0; i < 10; i++) {
wiringPiI2CWrite(fd, ON);
delay(770);
wiringPiI2CWrite(fd, OFF);
delay(770);
}
wiringPiI2CWrite(fd, OFF); wiringPiI2CWrite(fd, OFF);
if (wiringPiI2CRead(fd) == OFF) { if (wiringPiI2CRead(fd) == OFF) {
printf("LIGHT OFF!\n"); printf("LIGHT OFF!\n");
} }
}
void useADC() {
int fd = wiringPiI2CSetup(ADC);
cout << wiringPiI2CRead(fd) << endl;
takeARide(600);
for (int i = 0; i < 10; i++)
{
cout << wiringPiI2CRead(fd) << endl;
delay(500);
}
StopTheRide();
cout << wiringPiI2CRead(fd) << endl;
}
void takeARide(int speed) {
int wheelSpeed = speed;
if (wiringPiSetup() == -1) {
printf("WiringPiSetup failed\n");
exit(EXIT_FAILURE);
}
pinMode(PWM_PIN_RIGHT, PWM_OUTPUT);
pinMode(PWM_PIN_LEFT, PWM_OUTPUT);
pinMode(M1DIR_RIGHT, OUTPUT);
pinMode(M2DIR_LEFT, OUTPUT);
printf("pin ready !\n");
digitalWrite(M1DIR_RIGHT, 1);
digitalWrite(M2DIR_LEFT, 0);
pwmWrite(PWM_PIN_RIGHT, wheelSpeed);
pwmWrite(PWM_PIN_LEFT, wheelSpeed);
printf("There we go !\n");
}
void StopTheRide() {
printf("And we stop\n");
pwmWrite(PWM_PIN_RIGHT, 0);
pwmWrite(PWM_PIN_LEFT, 0);
}
int main(int argc, char const *argv[]) {
string answer;
cout << "led or adc ?" << endl;
cin >> answer ;
if (answer == "led") useTheLED();
else if (answer == "adc") {
useADC();
}
return 0; return 0;
} }
...@@ -6,8 +6,8 @@ switch : compile_switch ...@@ -6,8 +6,8 @@ switch : compile_switch
motor : compile_motor motor : compile_motor
sudo ./motor sudo ./motor
led : compile_LED i2c : compile_LED
sudo ./led sudo ./i2c
# compilations # compilations
...@@ -18,8 +18,8 @@ compile_motor : ...@@ -18,8 +18,8 @@ compile_motor :
gcc -o motor motor.c -lwiringPi gcc -o motor motor.c -lwiringPi
compile_LED : compile_LED :
g++ -o led I2C.cpp -lwiringPi g++ -o i2c I2C.cpp -lwiringPi
.PHONY : clean .PHONY : clean
clean : clean :
rm -rf switch motor led rm -rf switch motor led i2c
...@@ -14,9 +14,10 @@ const int ENC_PIN_2A = 35; //from FPGA to ENCODER -> ouput data from encod ...@@ -14,9 +14,10 @@ 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 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 = 14; //from RASPI to FPGA -> clock signal
const int SCK_PIN_FPGA = 13; //from FPGA to ENCODER -> clock signal const int SCK_PIN_FPGA = 13; //from FPGA to ENCODER -> clock signal
const int SS_BAR_1 = 10; //CE0 from RASPI to FPGA -> enable encoder const int SS_PIN_1 = 10; //CE0 from RASPI to FPGA -> enable encoder
const int SS_BAR_2 = 11; //CE1 from RASPI to FPGA -> enable encoder const int SS_PIN_2 = 11; //CE1 from RASPI to FPGA -> enable encoder
const int CE0_PIN_FPGA = 11;
const int CE1_PIN_FPGA = 11;
int main(int argc, char const *argv[]) int main(int argc, char const *argv[])
{ {
if (wiringPiSetup() == -1) { if (wiringPiSetup() == -1) {
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter