diff --git a/Lab3SAP/Lab3SAP.ino b/Lab3SAP/Lab3SAP.ino new file mode 100644 index 0000000..4668986 --- /dev/null +++ b/Lab3SAP/Lab3SAP.ino @@ -0,0 +1,76 @@ +#include +Servo Scale; + +int outputPinServoMotor = 10; +int const sampleSize = 50; +double sampleArray[sampleSize]; +int const inputPinSensor = 0; + +void setup() { +Serial.begin(115200); + Scale.attach(outputPinServoMotor); + + /*TCCR2A = 0; + TCCR2B = 0; + TCNT2 = 0; + + OCR2A = 250; + TCCR2A |= (1 << WGM21); + TCCR2B |= (1 << CS21) | (1 << CS20); + TIMSK2 |= (1 << OCIE2A); + sei();*/ + +} + +void loop() { + // put your main code here, to run repeatedly: + + + delay(10); + int val = analogRead(inputPinSensor); + addval(val); + + + int servoVal = sensorValToServoVal(getAVG()); + Serial.println(servoVal); + + Scale.write(servoVal); + +} + +/*ISR(TIMER2_COMPA_vect){ + TCNT1 = 0; + int val = analogRead(inputPinSensor); + addval(val); + //Serial.println(val); +}*/ + +void addval(int val) +{ + // we need to add the val at the start of the array + for (int i=0; i