ellis13 | Oui, j'utilise le PWM, mais je n'ai pas l'impression de l'utiliser correctement.
Code :
- uint8_t rxspeed[8] = {0xA5, 0x5A, 0x06, 0x82, 0x00, 0x01, 0x00, 0x00};
- uint8_t rxdose[8] = {0xA5, 0x5A, 0x06, 0x82, 0x00, 0x02, 0x00, 0x00};
- uint8_t rxrf[8] = {0xA5, 0x5A, 0x06, 0x82, 0x00, 0x03, 0x00, 0x00};
- uint8_t aa;
- uint8_t Recieved[40];
- uint32_t PWM_DUTY=20;//占空比
- void setup() {
- // put your setup code here, to run once:
- Serial.begin(115200);
- pinMode(3, OUTPUT);
- pinMode(9, OUTPUT);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- if(Serial.available() != 0)
- {
- for(aa = 0; aa < 8; aa ++)
- {
- Recieved[aa] = Serial.read();
- }
- switch(Recieved[4])
- {
- case 0x01://speed
- rxspeed[7] = Recieved[7];
- Serial.write(rxspeed, 8);
- break;
- case 0x02://dose
- rxdose[7] = Recieved[7];
- Serial.write(rxdose, 8);
- break;
- case 0x03://rf
- rxrf[7] = Recieved[7];
- Serial.write(rxrf, 8);
- break;
- default:
- break;
- }
- }
- analogWrite(3,rxspeed[7]);
- analogWrite(9,rxdose[7]);
- }
|
|