Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
summing long int
//gcc 7.4.0 #include <stdio.h> #include <stdbool.h> #include <util/delay.h> unsigned int v30sns = 0; // used in ADC for sensing battery volt unsigned int v30sns_lowest = 4095; // used in ADC for sensing battery volt unsigned int v30sns_highest = 0; // used in ADC for sensing battery volt unsigned int v30sns_mean = 0; // used in ADC for sensing battery volt unsigned long v30sns_sum = 0; // used in ADC for sensing battery volt unsigned int v30sns_count = 0; // used in ADC for sensing battery volt bool v30sns_ready = false; // used in ADC for sensing battery volt extern unsigned int adc(void); int main(void) { printf("Hello, world!\n"); while(1) { adc(); if ( v30sns <= v30sns_lowest ) { v30sns_lowest = v30sns; } if ( v30sns >= v30sns_highest ) { v30sns_highest = v30sns; } printf(" lowest: %i v30sns: %i highest: %i count %i sum %i mean %i \r\n", v30sns_lowest, v30sns, v30sns_highest, v30sns_count, v30sns_sum, v30sns_mean ); delayms(1000); } return 0; } // end main() unsigned int adc(void) { unsigned int data = 0; // Read the ADC conversion result ((unsigned char *) &data)[0] = 0x6A; ((unsigned char *) &data)[1] = 0x0E; // sum data for averaging final result v30sns_sum = v30sns_sum + (unsigned long) data; v30sns_count = v30sns_count + 1; // average sum after a few convertions and update global variable if ( v30sns_count >= 254) { v30sns = v30sns_sum / v30sns_count; v30sns_count = 0; v30sns_ready = 1; } return 0; // v30sns = data; }
run
|
edit
|
history
|
help
0
cstructCricPoint
tickeParsing.c
Data Types
a>=0 && b>=a
Intro to Arrays with comments
Lab 9 v0.95
fgets and basic string manipulation
CreverseInt
2
709 lab 3.1