Jump to content
43oh

Recommended Posts

So we are doing a project where we gonna use 3 UV sensors.

 

I was just wondering how can we use the code more than one time?

Like how can we triple it?

 

this is the code.  

 

 



/*
  AnalogReadSerial
  Reads an analog input on pin A3, prints the result to the serial monitor.
  Attach the center pin of a potentiometer to pin A3, and the outside pins to ~3V and ground.
  
  Hardware Required:
  * MSP-EXP430G2 LaunchPad
  * 10-kilohm Potentiometer
  * hook-up wire


  This example code is in the public domain.
*/


// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600); // msp430g2231 must use 4800
}


// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin A3:
  int sensorValue = analogRead(A1)* (3.3/4096.0); 
  // print out the value you read:
  Serial.println(sensorValue);
  delay(1); // delay in between reads for stability
}

Edited by bluehash
Please use code tags for easy code readability.
Link to post
Share on other sites

Could do something like this:

/*
Triple AnalogReadSerial based on AnalogReadSerial
Reads analog inputs on pins A1, A2 and A3, prints the results to the serial monitor.
Attach the center pins of potentiometers to pins A1, A2 and A3, and the outside pins to ~3V and ground.

Hardware Required:
  * MSP-EXP430G2 LaunchPad
  * Three 10-kilohm Potentiometers
  * hook-up wires

This example code is in the public domain.
*/

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600); // msp430g2231 must use 4800
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin A1:
  int sensorValue1 = analogRead(A1)* (3.3/4096.0);
  // print out the value you read:
  Serial.println("Sensor 1 value: ");
  Serial.println(sensorValue1);

  // read the input on analog pin A2:
  int sensorValue2 = analogRead(A2)* (3.3/4096.0);
  // print out the value you read:
  Serial.println("Sensor 2 value: ");
  Serial.println(sensorValue2);
  
  // read the input on analog pin A3:
  int sensorValue3 = analogRead(A3)* (3.3/4096.0);
  // print out the value you read:
  Serial.println("Sensor 3 value: ");
  Serial.println(sensorValue3);

  delay(500); // delay in between reads for stability and readability
}
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...