Le PMCBot est la nouvelle mascotte du PMCLab. Sa version de base est terminée, mais nous allons l'améliorer en lui donnant un beau PCB.
Code du PMCBot :
#include <RFduinoGZLL.h> device_t role = HOST; #define M1_AVANT 2 #define M1_ARRIERE 3 #define M2_AVANT 4 #define M2_ARRIERE 5 int vitesse = 0; int angle = 0; void setup() { pinMode(M1_AVANT, OUTPUT); pinMode(M1_ARRIERE, OUTPUT); pinMode(M2_AVANT, OUTPUT); pinMode(M2_ARRIERE, OUTPUT); RFduinoGZLL.begin(role); } void loop() { int vG = vitesse + angle; int vD = vitesse - angle; if (vG>0) { analogWrite(M1_AVANT, vG); digitalWrite(M1_ARRIERE, 0); } else { digitalWrite(M1_AVANT, 0); analogWrite(M1_ARRIERE, -vG); } if (vD>0) { analogWrite(M2_AVANT, vD); digitalWrite(M2_ARRIERE, 0); } else { digitalWrite(M2_AVANT, 0); analogWrite(M2_ARRIERE, -vD); } } void RFduinoGZLL_onReceive(device_t device, int rssi, char *data, int len) { if (device == DEVICE0) { vitesse = (data[1]-6)*33; angle = 90-(data[0]-1)*18; } }
Code du PMCBotJoystick :
#include <RFduinoGZLL.h> device_t role = DEVICE0; #define Y_PIN 2 #define X_PIN 3 void setup() { pinMode(Y_PIN, INPUT); pinMode(X_PIN, INPUT); RFduinoGZLL.begin(role); } void loop() { int x = analogRead(X_PIN)/100; int y = analogRead(Y_PIN)/100; char data[2]; data[0] = (char)(x+1); data[1] = (char)(y+1); RFduinoGZLL.sendToHost(data); delay(50); } void RFduinoGZLL_onReceive(device_t device, int rssi, char *data, int len) { }