just clarifying:
for the qn here:
Write a single Arduino program which does the following:
1.Read the value (name the variable flexValue) of a “flex sensor” that is connected to analog input AN0 of the Arduino. The value will be a 10-bit integer number having a value between 0 and 1023 inclusive, although flexing the sensor strip might not give values that cover the full range.
2.Read the value (potValue) of a potentiometer connected to analog input AN1. The value will be a 10-bit integer, similar to flexValue.
3.Output a value (dcSpeed) to a DC motor that is connected to digital pin 10 of the Arduino. This pin gives a ‘pulse-width modulated’ (PWM) output that switches rapidly between +0V and +5V to give the effect of a voltage that can vary continuously between these values. An Arduino output pin cannot provide enough current to drive the DC motor in the SIK so a transistor must be used to
increase the current.
4.Output a value (servoPosition) to a position servo that is connected to digital pin 11 of the Arduino.
5.Output the values ofthe four variables potValue, servoPosition, flexValue and dcSpeed to the serial monitor in the form of commaseparated variables (CSVs), without spaces. Each line must finish with new line character '\n', which is automatically inserted by Serial.println(). An example of a suitable print of CSVs is 815,148,846,198.
This is the program ive got: Is this correct?
// assign variable flexValue value of analog input AN0
int flexValue = analogRead(A0);
// the setup routine runs once when you press reset:
#define POTPIN A1
// select the input pin for the potentiometer
// Initialise to a known value
int potValue = POTPIN;
// the setup routine runs once when you press reset:
int motorPin = 10; // Connect the base of the transistor to pin 10.
// Even though it's not directly connected to the motor,
// we'll call it the 'motorPin'
int dcSpeed = motorPin;
#include <Servo.h>
// assign name to servo control object as servo1
Servo servo1;
int servoPosition = 90; /* assign value to variable seroPosition as 90, meaning the intended
angle of rotation of servo is 90 degrees, as chosen by us */
void setup()
{
pinMode( POTPIN, INPUT ); // Configure the potpin as an input
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
servo1.attach(11); //Connect the servo to pin 11
//with a minimum pulse width of
//900 and a maximum pulse width of
//2100.
}
// the loop routine runs over and over again forever:
void loop()
{
// read the input on analog pin 0:
int flexValue = analogRead(A0);
// print out the value you read as 'flexValue'
Serial.printIn("flexValue");
Serial.print(flexValue);
// delay in between reads for stability
delay(1000);
// read the input on analog pin:
int potValue = analogRead(POTPIN);
// print out the value you read, as 'potValue'
Serial.printIn("potValue");
Serial.print(potValue);
// delay in between reads for stability
delay(1000);
// Next, replicate a blink, but with the motorPin instead.
int onTime = 3000; // milliseconds to turn the motor on
int offTime = 3000; // milliseconds to turn the motor off
digitalWrite(motorPin, 255); // turn the motor on (full speed)
delay(onTime); // delay for onTime milliseconds
digitalWrite(motorPin, 0); // turn the motor off
delay(offTime); // delay for offTime milliseconds
/* To control a servo, give it the angle you'd like it
to turn to. Servos cannot turn a full 360 degrees, but
can tell it to move anywhere between 0 and 180 degrees.
Here, we are giving this value to be 90 degrees, as chosen by us*/
// Change position at full speed:
servo1.write(servoPosition); // Tell servo to go to 90 degrees
delay(1000); // delay for 1s(1000ms) for stability
servo1.write(0); // return to original position
delay(1000); // delay for 1s(1000ms) for stability
}
//Print the values of flexValue, potValue, dcSpeed and servoPosition onto the serial monitor, in the form of CSV
serial.PrintIn("flexValue");
serial.PrintIn(flexValue);
serial.printIn("potValue");
serial.PrintIn(potValue);
serial.PrintIn("dcSpeed");
serial.Print(dcSpeed);
serial.PrintIn("servoPosition");
serial.PrintIn(servoPosition);