Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int maxReading=0;
- int maxIndex=0;
- int readings[8];
- void goRead(int readIndex) {
- // see what the analog value is
- int currentReading = analogRead(A0);
- // is it bigger than our already known max value?
- if (currentReading > maxReading) {
- // okay, save the max value and the index that it happened
- maxReading = currentReading;
- maxIndex = readIndex;
- }
- // store our readings, for ... reasons?
- readings[readIndex] = currentReading;
- }
- void setup() {
- // put your setup code here, to run once:
- }
- void loop() {
- //reset your maxes
- maxReading = 0;
- maxIndex=0;
- // whatever happens, first read
- goRead(0);
- // more stuff happens
- goRead(1);
- // more stuff happens
- goRead(2);
- // more stuff happens
- goRead(3);
- // more stuff happens
- goRead(4);
- // more stuff happens
- goRead(5);
- // more stuff happens
- goRead(6);
- // more stuff happens
- goRead(7);
- // maxReading and maxIndex are your max values...
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement