Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This problem is in concern of arduino Write a program which will read in the CSV code and generate several things: The mean and standard

This problem is in concern of arduino

Write a program which will read in the CSV code and generate several things:

The mean and standard deviation for the Potentiometer readings

The mean and standard deviation for the Temperature readings

The mean and standard deviation for the Light sensor readings

A count of how many times each button was read as depressed

A line graph containing the pot, temp, and light readings over time with the linear approximation of each data set. The pot line should be purple, the temp line should be red, and the light line should be blue.

All graphs should be properly labeled.

Present this information in an obvious and attractive manner

///////////////////////////////////////////////////////////////////////////// // Symbolic Constants

#define LED0 11 #define LED1 9 #define LED2 6 #define LED3 3 #define SPKR 5 #define SRVO 10 #define RED 11 #define GREEN 9 #define BLUE 6

#define SW0 12 #define SW1 8 #define SW2 7 #define SW3 4 #define TEMP A0 #define POT A1 #define LIGHT A2

#define ANAINMAX 1023.0 // enter the max value for analog reads her #define ANAOUTMAX 255 // enter the max value for analog writes here

#define BAUD 9600 #define SAMPLES 25

int const MEASUREDELAY = 20;

///////////////////////////////////////////////////////////////////////////// // setup void setup() { pinMode( LED0, OUTPUT ); pinMode( LED1, OUTPUT ); pinMode( LED2, OUTPUT ); pinMode( LED3, OUTPUT ); pinMode( SPKR, OUTPUT ); pinMode( SRVO, OUTPUT ); pinMode( SW0, INPUT_PULLUP ); pinMode( SW1, INPUT_PULLUP ); pinMode( SW2, INPUT_PULLUP ); pinMode( SW3, INPUT_PULLUP ); pinMode( TEMP, INPUT_PULLUP ); pinMode( POT, INPUT_PULLUP ); pinMode( LIGHT, INPUT_PULLUP ); Serial.begin( BAUD ); }

///////////////////////////////////////////////////////////////////////////// // loop void loop() { int switch0 = 0; int switch1 = 0; int switch2 = 0; int switch3 = 0; float temperature = 0; float pot = 0; float light = 0;

int counter = 0; wait_for_start(); for( counter = 0; counter < SAMPLES; ++counter ) { read_switches( &switch0, &switch1, &switch2, &switch3 ); pot = read_pot( POT ); temperature = read_temp( TEMP ); light = read_light( LIGHT ); set_LEDs( switch0, switch1, switch2, switch3, pot, temperature, light ); print_stats( switch0, switch1, switch2, switch3, pot, temperature, light, MEASUREDELAY );

delay(MEASUREDELAY); } mark_end(); }

///////////////////////////////////////////////////////////////////////////// // wait_for_start // Waits for a keypress in the Serial window void wait_for_start() { Serial.print("Press and release switch 0 "); while( HIGH == digitalRead(SW0) ) //while its not being pressed do nothing, just wait { } Serial.print("Release switch 0 "); while( LOW == digitalRead(SW0) ) //while button is pressed print release switch0 and wait { } //after button is released continue go to for statment }

///////////////////////////////////////////////////////////////////////////// // read_switches // Reads the state of the four switches and updates passed in variables void read_switches( int *switch0, int *switch1, int *switch2, int *switch3 ) { *switch0 = digitalRead( SW0 ); *switch1 = digitalRead( SW1 ); *switch2 = digitalRead( SW2 ); *switch3 = digitalRead( SW3 ); }

///////////////////////////////////////////////////////////////////////////// // read_pot // Reads the potentiometer and returns its value as a percentage of the range float read_pot( float port ) { float pot = analogRead( port ); return pot / ANAINMAX; }

///////////////////////////////////////////////////////////////////////////// // read_temp // Reads the temp sensor and returns its value as a percentage of the range float read_temp( float port ) { float temp = analogRead( port ); return temp / ANAINMAX; }

///////////////////////////////////////////////////////////////////////////// // read_light // Reads the light sensor and returns its value as a percentage of the range float read_light( float port ) { float light = analogRead( port ); return light / ANAINMAX; }

///////////////////////////////////////////////////////////////////////////// // set_LEDs void set_LEDs( int switch0, int switch1, int switch2, int switch3, float pot, float temperature, float light ) { if( LOW == switch0 ) { analogWrite( LED0, pot * ANAOUTMAX ); } else { digitalWrite( LED0, LOW ); }

if( LOW == switch1 ) { analogWrite( LED1, temperature * ANAOUTMAX ); } else { digitalWrite( LED1, LOW ); }

if( LOW == switch2 ) { analogWrite( LED2, light * ANAOUTMAX ); } else { digitalWrite( LED2, LOW ); } if ( LOW == switch3 ) { analogWrite( LED3, ((pot + temperature + light) / 3.0) * ANAOUTMAX ); } else { digitalWrite( LED3, LOW ); } }

///////////////////////////////////////////////////////////////////////////// // print_stats // prints settings to console window void print_stats( int switch0, int switch1, int switch2, int switch3, float pot, float temperature, float light,int MEASUREDELAY ) { static int counter = 0; counter += MEASUREDELAY; Serial.print("time: "); Serial.print(counter); Serial.print(" ms "); Serial.print("switch0: "); Serial.print(switch0); Serial.print(" "); Serial.print("switch1: "); Serial.print(switch1); Serial.print(" "); Serial.print("switch2: "); Serial.print(switch2); Serial.print(" "); Serial.print("switch3: "); Serial.print(switch3); Serial.print(" "); Serial.print("potentiometer: "); Serial.print(pot); Serial.print(" "); Serial.print("temperature: "); Serial.print(temperature); Serial.print(" "); Serial.print("light: "); Serial.print(light); Serial.print(" "); Serial.print("--------------------------- "); }

///////////////////////////////////////////////////////////////////////////// // mark_end // marks the end of a run int mark_end() { Serial.print("ENDENDENDENDENDENDENDENDENDENDENDENDENDEND "); }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database System

Authors: Elmasri Ramez And Navathe Shamkant

7th Edition

978-9332582705

More Books

Students also viewed these Databases questions