ct demo
This commit is contained in:
		
							parent
							
								
									10b55e5aa5
								
							
						
					
					
						commit
						f82a0cc732
					
				
					 2 changed files with 26 additions and 7 deletions
				
			
		|  | @ -1,7 +1,8 @@ | |||
| #include <user_code.hpp> | ||||
| 
 | ||||
| //Timer Components
 | ||||
| ESPMega_Timer timer1(0, 50, timer1_callback, 15001); | ||||
| // Timer Components
 | ||||
| ESPMega_Timer timer1(0, 50, timer1_callback, 15001); // Using Memmory Address 15001
 | ||||
| ESPMega_CT ct0 = ESPMega_CT(0, adc2watts, 15002);    // Using Memory Address 15002-15017
 | ||||
| 
 | ||||
| // Display Componets
 | ||||
| // Link with Dual state button object with id 2 on page 1 named bt0
 | ||||
|  | @ -32,6 +33,7 @@ This code will run after every component is initialized | |||
| void user_init() | ||||
| { | ||||
|     timer1.begin(); | ||||
|     ct0.begin(); | ||||
|     ESPMega_EXTLCD.print("page home"); | ||||
|     ESPMega_EXTLCD.write(0xFF); | ||||
|     ESPMega_EXTLCD.write(0xFF); | ||||
|  | @ -45,6 +47,7 @@ This code will run once every event loop | |||
| void user_loop() | ||||
| { | ||||
|     nexLoop(nex_listen_list); | ||||
|     ct0.loop(); | ||||
| } | ||||
| 
 | ||||
| /*
 | ||||
|  | @ -82,14 +85,28 @@ void timer1_callback() | |||
|     } | ||||
| } | ||||
| 
 | ||||
| void ac_changed_user_callback(int mode, int temperature, int fan_speed) { | ||||
|      | ||||
| void ac_changed_user_callback(int mode, int temperature, int fan_speed) | ||||
| { | ||||
| } | ||||
| 
 | ||||
| void mqtt_connected_user_callback() { | ||||
| 
 | ||||
| void mqtt_connected_user_callback() | ||||
| { | ||||
| } | ||||
| 
 | ||||
| void user_state_request_callback() { | ||||
| 
 | ||||
| void user_state_request_callback() | ||||
| { | ||||
| } | ||||
| 
 | ||||
| float adc2watts(uint16_t adc_value) | ||||
| { | ||||
|     const float RATIO = 0.1; | ||||
|     const float BURDEN_RESISTANCE = 20; | ||||
|     const float VOLTAGE = 220; | ||||
|     const uint16_t ADC_RANGE_START = 500; | ||||
|     const uint16_t ADC_RANGE_END = 16000; | ||||
|     const float ADC_RANGE = 12; | ||||
|     float burden_voltage = (adc_value - ADC_RANGE_START) / (ADC_RANGE_END - ADC_RANGE_START) * ADC_RANGE; | ||||
|     float secondary_current = burden_voltage / BURDEN_RESISTANCE; | ||||
|     float primary_current = secondary_current / RATIO; | ||||
|     return primary_current * VOLTAGE; | ||||
| } | ||||
|  | @ -5,6 +5,7 @@ | |||
| #include <PubSubClientTools.h> | ||||
| #include "espmega_iot_timer.hpp" | ||||
| #include "espmega_iot_external_lcd.hpp" | ||||
| #include "espmega_iot_emon.hpp" | ||||
| 
 | ||||
| // External LCD Configuration
 | ||||
| #define ENABLE_EXTERNAL_LCD | ||||
|  | @ -27,6 +28,7 @@ void timer1_callback(); | |||
| void mqtt_connected_user_callback(); | ||||
| void bt0PopCallback(void *ptr); | ||||
| void user_state_request_callback(); | ||||
| float adc2watts(uint16_t adc_value); | ||||
| 
 | ||||
| 
 | ||||
| // ESPMega IoT Core Build-in Functions
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue