diff options
| author | Rishi-k-s <rishikrishna.sr@gmail.com> | 2024-07-03 21:03:32 +0530 |
|---|---|---|
| committer | Rishi-k-s <rishikrishna.sr@gmail.com> | 2024-07-03 21:03:32 +0530 |
| commit | ad1163154c61db7a8ebf44110f786c219d0bbc5b (patch) | |
| tree | 86e4c4a6f68e5b8a3785dbd4c097b143e9b17f52 | |
| parent | 7bcf5e86b3771cc37c7284e891fc6120c64e99ad (diff) | |
finished the test code v1.0a
| -rw-r--r-- | test/test.ino | 65 |
1 files changed, 32 insertions, 33 deletions
diff --git a/test/test.ino b/test/test.ino index c567101..845c5ea 100644 --- a/test/test.ino +++ b/test/test.ino @@ -2,29 +2,25 @@ #include <Adafruit_PWMServoDriver.h> Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(); -uint8_t value = 0; -uint8_t counter =0; +uint16_t value = 0; // Use uint16_t for a wider range of values +uint8_t counter = 0; #define SERVOMIN 150 // This is the 'minimum' pulse length count (out of 4096) #define SERVOMAX 600 // This is the 'maximum' pulse length count (out of 4096) void setup() { - // put your setup code here, to run once: Serial.begin(9600); + + Serial.println("------------------------"); Serial.println("Servo Tester v1.0a"); Serial.println("Enter Servo Value"); - // Serial.println("1"); - // Serial.println("2"); - // Serial.println("3"); - // Serial.println("4"); - // Serial.println("5"); - // Serial.println("6"); - + Serial.println("If its 2 digit values enter it with 0 as prefix"); + Serial.println("Eg: for 90, type 090"); + Serial.println("------------------------"); + pwm.begin(); pwm.setOscillatorFrequency(27000000); - pwm.setPWMFreq(50); - - + pwm.setPWMFreq(50); } void loop() { @@ -36,29 +32,32 @@ void loop() { Serial.print("received: "); Serial.println(incomingByte); - //Assuming that i only give 3 digit values - if(counter == 0){ - value = (incomingByte - '0') * 100; - } - else if(counter == 1){ - value += (incomingByte - '0')*10; + // Convert ASCII to integer + uint8_t digit = incomingByte - '0'; + + // Validate that the input is a digit + if (digit >= 0 && digit <= 9) { + // Assuming that I only give 3 digit values + if (counter == 0) { + value = digit * 100; + } + else if (counter == 1) { + value += digit * 10; + } + else if (counter == 2) { + value += digit; + } + Serial.print("value: "); + Serial.println(value); + + counter++; } - else if(counter == 2){ - value += (incomingByte - '0')*1; - }; - Serial.println("value"); - Serial.println(value); - - counter++ ; } - if(counter ==3){ + if (counter == 3) { Serial.println(value); - pwm.setPWM(1, 0, value); - counter =0; - value =0; + pwm.setPWM(4, 0, value); // Arguement order => (PWM Driver Pin, 0, val of servo) + counter = 0; + value = 0; // Reset value after using it } - } - - |
