Ви не увійшли.
ааа, сбили с толку,
тот код что у вас не будет ничего опрашивать у него задача PWM выдать по графику
щас пришлю другой вариант )
необходимо убрать из кода,
// #define NO_EXT_KEY
но я кнопки не проверял, это сами
пасиб за мыло, заработался, забыл проверять все папки ) писем - море черное )
/*
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 00):
* <devgate.info эт gmail.com> wrote this file. As long as you retain this notice you
* can do whatever you want with this stuff. If we meet some day, and you think
* this stuff is worth it, you can buy me a beer or device ( arduino-ua.com ) in return.
* Chingiz Sunlucid
* ----------------------------------------------------------------------------
* Date create: 2016.09.24
* Date change: 2016.09.29
* ----------------------------------------------------------------------------
*/
// ARDUINO PIN CONFIG
// for example
// Arduino leonardo
/*
Input and Output
Each of the 20 digital i/o pins on the Leonardo can be used as an input or output, using pinMode(), digitalWrite(), and digitalRead() functions. They operate at 5 volts. Each pin can provide or receive a maximum of 40 mA and has an internal pull-up resistor (disconnected by default) of 20-50 kOhms. In addition, some pins have specialized functions:
Serial: 0 (RX) and 1 (TX). Used to receive (RX) and transmit (TX) TTL serial data using the ATmega32U4 hardware serial capability. Note that on the Leonardo, the Serial class refers to USB (CDC) communication; for TTL serial on pins 0 and 1, use the Serial1 class.
TWI: 2 (SDA) and 3 (SCL). Support TWI communication using the Wire library.
External Interrupts: 3 (interrupt 0), 2 (interrupt 1), 0 (interrupt 2), 1 (interrupt 3) and 7 (interrupt 4). These pins can be configured to trigger an interrupt on a low value, a rising or falling edge, or a change in value. See the attachInterrupt() function for details.
PWM: 3, 5, 6, 9, 10, 11, and 13. Provide 8-bit PWM output with the analogWrite() function.
SPI: on the ICSP header. These pins support SPI communication using the SPI library. Note that the SPI pins are not connected to any of the digital I/O pins as they are on the Uno, They are only available on the ICSP connector. This means that if you have a shield that uses SPI, but does NOT have a 6-pin ICSP connector that connects to the Leonardo's 6-pin ICSP header, the shield will not work.
LED: 13. There is a built-in LED connected to digital pin 13. When the pin is HIGH value, the LED is on, when the pin is LOW, it's off.
Analog Inputs: A0-A5, A6 - A11 (on digital pins 4, 6, 8, 9, 10, and 12). The Leonardo has 12 analog inputs, labeled A0 through A11, all of which can also be used as digital i/o. Pins A0-A5 appear in the same locations as on the Uno; inputs A6-A11 are on digital i/o pins 4, 6, 8, 9, 10, and 12 respectively. Each analog input provide 10 bits of resolution (i.e. 1024 different values). By default the analog inputs measure from ground to 5 volts, though is it possible to change the upper end of their range using the AREF pin and the analogReference() function.
There are a couple of other pins on the board:
AREF. Reference voltage for the analog inputs. Used with analogReference().
Reset. Bring this line LOW to reset the microcontroller. Typically used to add a reset button to shields which block the one on the board.
*/
// potentiometer wiper (middle terminal) connected to analog pin
//int input_array_pin[] = { A0,A1,A2,A3,A4 };
const int input_array_pin[] = { 4,6,8,9,10 };
const int out_pwm_pin = 3;
const int digi_start_pin = 12;
const int LED_PIN_DEMO = 13; /* use PWM, for control */
#define DEBUG
#define DEBUG_PWM
// #define NO_EXT_KEY
#define DEBOUNCE_TIME 100
#define TASK_PROCESS_TIME 10
/*
DEBUG - view status exe system >> debug uart
DEBUG_PWM - view change PWM >> debug uart
NO_EXT_KEY - no use user keybord, for check system
DEBOUNCE_TIME 100
TASK_PROCESS_TIME 10 - 10 ms programm scheduler
*/
// 8 bit PWM
#define MAX_RESOLUTION_PWM 0xFF
// 16 bit PWM
// #define MAX_RESOLUTION_PWM 0xFFFF
typedef enum { // enum name task
ST_WAIT = 0,
ST_TIME_R2 = 1,
ST_TIME_R3 = 2,
ST_PWM_R4 = 3,
ST_TIME_R5 = 4,
}TE_STATE;
typedef enum {
TIMER_EXE = 0,
TIMER_DISABLED = 1,
TIMER_RUN = 2,
}TE_TIMER;
typedef enum { // noedit, name ( mem data sarray )
R1 = 0,
R2 = 1,
R3 = 2,
R4 = 3,
R5 = 4,
} TE_IO_NAME;
#define BIT(x) (1 << (x))
#define CHECKBIT(x,b) (x&(b))
#define SETBIT(x,b) x|=(b)
#define CLEARBIT(x,b) x&=~(b)
#define TOGGLEBIT(x,b) x^=(b)
#define count_element_array(x) sizeof(x)/sizeof(x[0])
char debug_str[100];
// uncomment for disable debug info, or delete line #define DEBUG
// #undef DEBUG
typedef struct {
unsigned long time_unit[5];
unsigned short pwm_unit [5];
unsigned short current_pwm; // for 16bit pwm chip
unsigned long time_start_key_press;
unsigned long time_start_key_un_press;
uint16_t key_status;
TE_STATE state;
} td_system;
typedef struct { // float not optimal, easy code
float pwm_start;
float pwm_end;
float pwm_delta;
float pwm_now;
unsigned long count_step;
} td_temp_falling;
td_system system_demo_pwm;
td_temp_falling temp_falling;
unsigned long get_value_from_percent ( unsigned long percent, unsigned long max_value );
unsigned long get_percent_from_value ( unsigned long xxx, unsigned long max_value );
void set_new_pwm ( unsigned short data );
void prepare_new_state ( TE_STATE new_state );
void decode_input_data ( void );
void manual_stop_system ( void );
TE_TIMER programm_count_down_uint16 ( unsigned short *timer , unsigned char shift );
TE_TIMER programm_count_down_uint32 ( unsigned long *timer , unsigned long shift );
TE_TIMER system_delay_uint32 ( unsigned long *timer , unsigned long shift );
void key_function ( void );
void event_task();
void get_analog_config_system (void);
// R1 - value PWM1 ( pwm_unit[0] )
// R2 - state1 time ( 0..10 sec ), PWM1 ( pwm_unit[1] )
// R3 - state2 time ( 0..10 sec ) ( pwm_unit[2] )
// R4 - state3 value PWM2 ( pwm_unit[3] )
// R5 - state4 time ( 0..10 sec ) ( pwm_unit[4] )
//---------------------------------------------------
int in_r_value[count_element_array(input_array_pin)]; // variable to store the value read
//---------------------------------------------------
// funtion provide hw setup system demo pwm.
void setup()
{
int foo;
system_demo_pwm.time_start_key_press = DEBOUNCE_TIME;
system_demo_pwm.time_start_key_un_press = DEBOUNCE_TIME;
for ( foo = 0; foo < count_element_array(input_array_pin); foo ++ )
{
// set mode pin input
}
pinMode (out_pwm_pin, OUTPUT); // sets the pin as output
pinMode (LED_PIN_DEMO, OUTPUT); // sets the pin as output
pinMode (digi_start_pin, INPUT); // sets the pin as input
Serial.begin(9600); // setup serial
prepare_new_state ( ST_WAIT );
}
unsigned long get_value_from_percent ( unsigned long percent, unsigned long max_value )
{
unsigned long ret;
// max_value - 100 %
// x percent
ret = (unsigned long)((unsigned long)max_value*(unsigned long)percent)/(unsigned long)100;
return (ret);
}
unsigned long get_percent_from_value ( unsigned long xxx, unsigned long max_value )
{
unsigned long ret;
// max_value - 100 %
// xxx percent
ret = (unsigned long)((unsigned long)xxx*(unsigned long)100/(unsigned long)max_value);
return (ret);
}
void set_new_pwm ( unsigned short data )
{
#ifdef DEBUG_PWM
static unsigned short old_pwm = 0xFFFF;
if ( data != old_pwm )
{
sprintf ( debug_str,"pwm: %d " ,data );
Serial.println ( debug_str );
old_pwm = data;
}
#endif
system_demo_pwm.current_pwm = data;
analogWrite ( out_pwm_pin, data );
#ifdef DEBUG
analogWrite ( LED_PIN_DEMO, data );
#endif
}
void prepare_new_state ( TE_STATE new_state )
{
#ifdef DEBUG
Serial.print("set new state "); Serial.println(new_state);
#endif
// system_demo_pwm.pwm_unit [R1];
// system_demo_pwm.time_unit [R2];
// system_demo_pwm.time_unit [R3];
// system_demo_pwm.pwm_unit [R4];
// system_demo_pwm.time_unit [R5];
switch ( new_state )
{
case ST_WAIT : // disable all
set_new_pwm ( 0 );
break;
case ST_TIME_R2 : // start
set_new_pwm ( system_demo_pwm.pwm_unit[R1] );
temp_falling.pwm_start = system_demo_pwm.pwm_unit[R1];
temp_falling.pwm_end = system_demo_pwm.pwm_unit[R1];
temp_falling.pwm_delta = 0;
break;
case ST_TIME_R3 : // falling
set_new_pwm ( system_demo_pwm.pwm_unit[R1] );
temp_falling.pwm_now = system_demo_pwm.current_pwm;
temp_falling.count_step = system_demo_pwm.time_unit[R3] / TASK_PROCESS_TIME;
temp_falling.pwm_start = system_demo_pwm.pwm_unit[R1];
temp_falling.pwm_end = system_demo_pwm.pwm_unit[R4];
temp_falling.pwm_delta = (temp_falling.pwm_start - temp_falling.pwm_end ) / (float)temp_falling.count_step;
break;
case ST_PWM_R4: // line
set_new_pwm ( system_demo_pwm.pwm_unit[R4] );
break;
case ST_TIME_R5:
set_new_pwm ( system_demo_pwm.current_pwm );
temp_falling.pwm_now = system_demo_pwm.current_pwm;
temp_falling.count_step = system_demo_pwm.time_unit[R5] / TASK_PROCESS_TIME;
temp_falling.pwm_start = system_demo_pwm.current_pwm;
temp_falling.pwm_end = 0;
temp_falling.pwm_delta = temp_falling.pwm_start / (float)temp_falling.count_step;
break;
}
system_demo_pwm.state = new_state;
}
//-------------------------------------------------------
void decode_input_data ( void )
{
int foo;
// R1 (0-1023) value PWM1
unsigned long ui_temp;
#define max_analog_digi_value ( 0x3FF )
#ifdef NO_EXT_KEY
in_r_value[R1] = max_analog_digi_value;
in_r_value[R2] = 512;
in_r_value[R3] = 128;
in_r_value[R4] = 512;
in_r_value[R5] = 512;
#endif
// get pwm1
ui_temp = get_percent_from_value( in_r_value[R1],max_analog_digi_value );
system_demo_pwm.pwm_unit[R1] = get_value_from_percent( ui_temp, MAX_RESOLUTION_PWM );
// get time1 R2
ui_temp = get_percent_from_value( in_r_value[R2],max_analog_digi_value );
system_demo_pwm.time_unit[R2] = get_value_from_percent( ui_temp,10000 ); // 10 sec
// get time2 R3
ui_temp = get_percent_from_value( in_r_value[R3],max_analog_digi_value );
system_demo_pwm.time_unit[R3] = get_value_from_percent( ui_temp,10000 ); // 10 sec
// disable incorrect time setting
if ( (system_demo_pwm.time_unit[R2] + system_demo_pwm.time_unit[R3]) > 10000 )
system_demo_pwm.time_unit[R3] = system_demo_pwm.time_unit[R2] / 2;
//-----------------------
// get pwm R4
ui_temp = get_percent_from_value( in_r_value[R4],max_analog_digi_value );
system_demo_pwm.pwm_unit[R4] = get_value_from_percent( ui_temp,MAX_RESOLUTION_PWM );
// get time R5
ui_temp = get_percent_from_value( in_r_value[R5],max_analog_digi_value );
system_demo_pwm.time_unit[R5] = get_value_from_percent( ui_temp,10000 ); // 10 sec
#ifdef DEBUG
for ( foo = 0; foo < 5; foo ++ )
{
switch ( foo )
{
case R2:
case R3:
case R5:
// Serial.print("time_unit["); Serial.print(foo); Serial.print("] = ");
// Serial.println( system_demo_pwm.time_unit[foo]);
sprintf ( debug_str,"time_unit[%d] = %d " ,foo, system_demo_pwm.time_unit[foo] );
Serial.println ( debug_str );
break;
default:
sprintf ( debug_str,"pwm_unit[%d] = %d " ,foo, system_demo_pwm.pwm_unit[foo] );
Serial.println ( debug_str );
break;
}
}
#endif
}
void manual_stop_system ( void )
{
prepare_new_state (ST_TIME_R5);
#ifdef DEBUG
int foo = ST_TIME_R5;
sprintf ( debug_str,"time_unit[%d] = %d " ,foo, system_demo_pwm.time_unit[foo] );
Serial.println ( debug_str );
sprintf ( debug_str,"pwm_unit[%d] = %d " ,foo, system_demo_pwm.pwm_unit[foo] );
Serial.println ( debug_str );
#endif
}
TE_TIMER programm_count_down_uint16 ( unsigned short *timer , unsigned char shift )
{
if (*timer > 0 )
{
if (*timer > shift )
{
*timer -= shift;
return TIMER_RUN;
}
else
{
*timer = 0;
return TIMER_EXE;
}
}
return TIMER_DISABLED;
}
TE_TIMER programm_count_down_uint32 ( unsigned long *timer , unsigned long shift )
{
if (*timer > 0 )
{
if (*timer > shift )
{
*timer -= shift;
return TIMER_RUN;
}
else
{
*timer = 0;
return TIMER_EXE;
}
}
return TIMER_DISABLED;
}
TE_TIMER system_delay_uint32 ( unsigned long *timer , unsigned long shift )
{
if ( *timer > 0 )
{
if (*timer > shift )
{
*timer -= shift;
return TIMER_RUN;
}
else
{ // save delta time
*timer = ( shift - *timer );
return TIMER_EXE;
}
}
return TIMER_DISABLED;
}
void key_function ( void )
{
#ifndef NO_EXT_KEY
TE_TIMER status;
if ( digitalRead(digi_start_pin))
{
status = programm_count_down_uint32 (&system_demo_pwm.time_start_key_press, TASK_PROCESS_TIME);
switch ( status )
{
case TIMER_EXE:
case TIMER_DISABLED:
system_demo_pwm.key_status = 1;
break;
}
} else {
system_demo_pwm.time_start_key_press = DEBOUNCE_TIME;
status = programm_count_down_uint32 (&system_demo_pwm.time_start_key_un_press, TASK_PROCESS_TIME);
switch ( status )
{
case TIMER_EXE:
case TIMER_DISABLED:
system_demo_pwm.key_status = 0;
break;
}
}
#endif
}
void event_task()
{
TE_TIMER status;
key_function ();
if ( system_demo_pwm.state == ST_WAIT ) return;
switch ( system_demo_pwm.state )
{
//----------------------------------------
case ST_TIME_R2:
// sprintf ( debug_str,"time [%d]" , system_demo_pwm.time_unit[R2] );
// Serial.println ( debug_str );
status = programm_count_down_uint32 (&system_demo_pwm.time_unit[R2], TASK_PROCESS_TIME);
switch ( status )
{
case TIMER_EXE:
case TIMER_DISABLED:
prepare_new_state(ST_TIME_R3);
break;
case TIMER_RUN:
break;
}
break;
//----------------------------------------
case ST_TIME_R3:
status = programm_count_down_uint32 (&temp_falling.count_step, 1);
switch ( status )
{
case TIMER_EXE:
case TIMER_DISABLED:
prepare_new_state(ST_PWM_R4);
break;
case TIMER_RUN:
if ( temp_falling.pwm_now > temp_falling.pwm_delta )
{
temp_falling.pwm_now -= temp_falling.pwm_delta;
} else temp_falling.pwm_now = 0;
set_new_pwm ( temp_falling.pwm_now );
break;
}
break;
//----------------------------------------
case ST_PWM_R4:
// analogWrite(out_pwm_pin, system_demo_pwm.pwm_unit[R4])
break;
//----------------------------------------
case ST_TIME_R5:
status = programm_count_down_uint32 (&temp_falling.count_step, 1);
switch ( status )
{
case TIMER_EXE:
case TIMER_DISABLED:
prepare_new_state(ST_WAIT);
break;
case TIMER_RUN:
if ( temp_falling.pwm_now > temp_falling.pwm_delta )
{
temp_falling.pwm_now -= temp_falling.pwm_delta;
} else temp_falling.pwm_now = 0;
set_new_pwm ( temp_falling.pwm_now );
break;
}
break;
//----------------------------------------
}
}
void get_analog_config_system (void)
{
int foo;
for ( foo = 0; foo < count_element_array(input_array_pin); foo ++ )
{
in_r_value[foo] = analogRead ( input_array_pin[foo] ); // read the input pin
}
}
void loop()
{
static unsigned long task_time;
static unsigned long key_time_start_press;
static unsigned long key_time_start_unpress;
TE_TIMER status;
static unsigned long hw_old_system_timer = 0;
unsigned long hw_current_system_timer = 0;
unsigned long delta_task_timer;
if ( system_demo_pwm.state == ST_WAIT )
{
if ( system_demo_pwm.key_status )
{
get_analog_config_system();
decode_input_data ( );
prepare_new_state (1);
}
}
else
{
if ( system_demo_pwm.state != ST_TIME_R5 )
if ( !system_demo_pwm.key_status ) manual_stop_system();
}
hw_current_system_timer = millis();
delta_task_timer = hw_current_system_timer - hw_old_system_timer;
hw_old_system_timer = hw_current_system_timer;
status = system_delay_uint32 ( &task_time, delta_task_timer );
switch ( status )
{
case TIMER_EXE:
case TIMER_DISABLED:
task_time += TASK_PROCESS_TIME;
event_task();
// Serial.println("exe");
break;
case TIMER_RUN:
break;
}
// - - - - - - - - - - -
#ifdef NO_EXT_KEY
if ( system_demo_pwm.state == ST_WAIT )
if ( system_demo_pwm.key_status == 0 )
{
// Serial.println(" key 0");
status = programm_count_down_uint32 ( &key_time_start_press, delta_task_timer );
switch ( status )
{
case TIMER_EXE:
case TIMER_DISABLED:
system_demo_pwm.key_status = 1;
key_time_start_unpress = 10000;
Serial.println("set key start");
break;
case TIMER_RUN:
break;
}
}
if ( system_demo_pwm.state == ST_PWM_R4 )
if ( system_demo_pwm.key_status == 1 )
{
status = programm_count_down_uint32 ( &key_time_start_unpress, delta_task_timer );
switch ( status )
{
case TIMER_EXE:
case TIMER_DISABLED:
system_demo_pwm.key_status = 0;
key_time_start_press = 5000;
Serial.println("set key end");
break;
case TIMER_RUN:
break;
}
}
#endif
}
сделайте файл ino на общем доступе, дропбокс, гугл драйв с правом редактировать для меня
кнопку вечером проверю
собрал макетку вне зависимости от напруги на потенциометрах графа
set new state 0
set key start
pwm_unit[0] = 255
time_unit[1] = 5000
time_unit[2] = 1200
pwm_unit[3] = 127
time_unit[4] = 5000
set new state 1
pwm: 255
не меняется и процедура циклично повторяется
Вход старт/стоп не отзывается...идет постоянное повторение процедуры.....
NoName Почту проверьте...
Ок, я тогда сам выберу)))) но пластик, кажется, не стоит так рано покупать, правильнее с других запчастей)))))
Завтра-послезавтра придут запчасти, буду пробовать схемку внедрять.....
ну вы и вопросы задаете )
что то я увлекся, навскидку тысяч 60 набежало ),
успокоился, и остановится на таком (см ниже )
а вообще то, спасибо будет достаточно
но списочек я на всякий случай прилагаю
любая штука из
http://arduino-ua.com/prod1728-gazovii- … orelka-fen
http://arduino-ua.com/prod651-Logichesk … _8_kanalov
http://arduino-ua.com/prod495-Shyp_dlya … afa_h1_h10
http://arduino-ua.com/prod1421-cifrovoi … etr-xl830l
http://arduino-ua.com/prod1564-nabor-ne … cetov-7sht-
http://arduino-ua.com/prod1620-wi-fi-mo … iya-esp-14
может начать принтер собирать? нужно же с чего то начинать )
http://arduino-ua.com/prod1654-abs-plas … -mm-0-4-kg
Предварительно работает))))Какую плюшку желаете?
Доброй ночи))завтра, если успею, обьязательно проверю)))...на работе автобус с блоком завис...
что там на ногах PWM сами разберитесь плс )
я посмотрю, но позже
исходники
/*
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 00):
* <devgate.info эт gmail.com> wrote this file. As long as you retain this notice you
* can do whatever you want with this stuff. If we meet some day, and you think
* this stuff is worth it, you can buy me a beer or device ( arduino-ua.com ) in return.
* Chingiz Sunlucid
* ----------------------------------------------------------------------------
* Date : 2016.09.24
* ----------------------------------------------------------------------------
*/
// ARDUINO PIN CONFIG
// for example
// Arduino leonardo
/*
Input and Output
Each of the 20 digital i/o pins on the Leonardo can be used as an input or output, using pinMode(), digitalWrite(), and digitalRead() functions. They operate at 5 volts. Each pin can provide or receive a maximum of 40 mA and has an internal pull-up resistor (disconnected by default) of 20-50 kOhms. In addition, some pins have specialized functions:
Serial: 0 (RX) and 1 (TX). Used to receive (RX) and transmit (TX) TTL serial data using the ATmega32U4 hardware serial capability. Note that on the Leonardo, the Serial class refers to USB (CDC) communication; for TTL serial on pins 0 and 1, use the Serial1 class.
TWI: 2 (SDA) and 3 (SCL). Support TWI communication using the Wire library.
External Interrupts: 3 (interrupt 0), 2 (interrupt 1), 0 (interrupt 2), 1 (interrupt 3) and 7 (interrupt 4). These pins can be configured to trigger an interrupt on a low value, a rising or falling edge, or a change in value. See the attachInterrupt() function for details.
PWM: 3, 5, 6, 9, 10, 11, and 13. Provide 8-bit PWM output with the analogWrite() function.
SPI: on the ICSP header. These pins support SPI communication using the SPI library. Note that the SPI pins are not connected to any of the digital I/O pins as they are on the Uno, They are only available on the ICSP connector. This means that if you have a shield that uses SPI, but does NOT have a 6-pin ICSP connector that connects to the Leonardo's 6-pin ICSP header, the shield will not work.
LED: 13. There is a built-in LED connected to digital pin 13. When the pin is HIGH value, the LED is on, when the pin is LOW, it's off.
Analog Inputs: A0-A5, A6 - A11 (on digital pins 4, 6, 8, 9, 10, and 12). The Leonardo has 12 analog inputs, labeled A0 through A11, all of which can also be used as digital i/o. Pins A0-A5 appear in the same locations as on the Uno; inputs A6-A11 are on digital i/o pins 4, 6, 8, 9, 10, and 12 respectively. Each analog input provide 10 bits of resolution (i.e. 1024 different values). By default the analog inputs measure from ground to 5 volts, though is it possible to change the upper end of their range using the AREF pin and the analogReference() function.
There are a couple of other pins on the board:
AREF. Reference voltage for the analog inputs. Used with analogReference().
Reset. Bring this line LOW to reset the microcontroller. Typically used to add a reset button to shields which block the one on the board.
*/
// potentiometer wiper (middle terminal) connected to analog pin
//int input_array_pin[] = { A0,A1,A2,A3,A4 };
const int input_array_pin[] = { 4,6,8,9,10 };
const int out_pwm_pin = 3;
const int digi_start_pin = 12;
const int LED_PIN_DEMO = 13; /* use PWM, for control */
// 8 bit PWM
#define MAX_RESOLUTION_PWM 0xFF
// 16 bit PWM
// #define MAX_RESOLUTION_PWM 0xFFFF
typedef enum { // enum name task
ST_WAIT = 0,
ST_TIME_R2 = 1,
ST_TIME_R3 = 2,
ST_PWM_R4 = 3,
ST_TIME_R5 = 4,
}TE_STATE;
typedef enum {
TIMER_EXE = 0,
TIMER_DISABLED = 1,
TIMER_RUN = 2,
}TE_TIMER;
typedef enum { // noedit, name ( mem data sarray )
R1 = 0,
R2 = 1,
R3 = 2,
R4 = 3,
R5 = 4,
} TE_IO_NAME;
#define BIT(x) (1 << (x))
#define CHECKBIT(x,b) (x&(b))
#define SETBIT(x,b) x|=(b)
#define CLEARBIT(x,b) x&=~(b)
#define TOGGLEBIT(x,b) x^=(b)
#define count_element_array(x) sizeof(x)/sizeof(x[0])
#define DEBUG
#define DEBUG_PWM
#define NO_EXT_KEY
char debug_str[100];
#define DEBOUNCE_TIME 100
#define TASK_PROCESS_TIME 10
// uncomment for disable debug info, or delete line #define DEBUG
// #undef DEBUG
typedef struct {
unsigned long time_unit[5];
unsigned short pwm_unit [5];
unsigned short current_pwm; // for 16bit pwm chip
unsigned long time_start_key_press;
unsigned long time_start_key_un_press;
uint16_t key_status;
TE_STATE state;
} td_system;
typedef struct { // float not optimal, easy code
float pwm_start;
float pwm_end;
float pwm_delta;
float pwm_now;
unsigned long count_step;
} td_temp_falling;
td_system system_demo_pwm;
td_temp_falling temp_falling;
unsigned long get_value_from_percent ( unsigned long percent, unsigned long max_value );
unsigned long get_percent_from_value ( unsigned long xxx, unsigned long max_value );
void set_new_pwm ( unsigned short data );
void prepare_new_state ( TE_STATE new_state );
void decode_input_data ( void );
void manual_stop_system ( void );
TE_TIMER programm_count_down_uint16 ( unsigned short *timer , unsigned char shift );
TE_TIMER programm_count_down_uint32 ( unsigned long *timer , unsigned long shift );
TE_TIMER system_delay_uint32 ( unsigned long *timer , unsigned long shift );
void key_function ( void );
void event_task();
void get_analog_config_system (void);
// R1 - value PWM1 ( pwm_unit[0] )
// R2 - state1 time ( 0..10 sec ), PWM1 ( pwm_unit[1] )
// R3 - state2 time ( 0..10 sec ) ( pwm_unit[2] )
// R4 - state3 value PWM2 ( pwm_unit[3] )
// R5 - state4 time ( 0..10 sec ) ( pwm_unit[4] )
//---------------------------------------------------
int in_r_value[count_element_array(input_array_pin)]; // variable to store the value read
//---------------------------------------------------
// funtion provide hw setup system demo pwm.
void setup()
{
int foo;
system_demo_pwm.time_start_key_press = DEBOUNCE_TIME;
system_demo_pwm.time_start_key_un_press = DEBOUNCE_TIME;
for ( foo = 0; foo < count_element_array(input_array_pin); foo ++ )
{
// set mode pin input
}
pinMode (out_pwm_pin, OUTPUT); // sets the pin as output
pinMode (LED_PIN_DEMO, OUTPUT); // sets the pin as output
pinMode (digi_start_pin, INPUT); // sets the pin as input
Serial.begin(9600); // setup serial
prepare_new_state ( ST_WAIT );
}
unsigned long get_value_from_percent ( unsigned long percent, unsigned long max_value )
{
unsigned long ret;
// max_value - 100 %
// x percent
ret = (unsigned long)((unsigned long)max_value*(unsigned long)percent)/(unsigned long)100;
return (ret);
}
unsigned long get_percent_from_value ( unsigned long xxx, unsigned long max_value )
{
unsigned long ret;
// max_value - 100 %
// xxx percent
ret = (unsigned long)((unsigned long)xxx*(unsigned long)100/(unsigned long)max_value);
return (ret);
}
void set_new_pwm ( unsigned short data )
{
#ifdef DEBUG_PWM
static unsigned short old_pwm = 0xFFFF;
if ( data != old_pwm )
{
sprintf ( debug_str,"pwm: %d " ,data );
Serial.println ( debug_str );
old_pwm = data;
}
#endif
system_demo_pwm.current_pwm = data;
analogWrite ( out_pwm_pin, data );
#ifdef DEBUG
analogWrite ( LED_PIN_DEMO, data );
#endif
}
void prepare_new_state ( TE_STATE new_state )
{
#ifdef DEBUG
Serial.print("set new state "); Serial.println(new_state);
#endif
// system_demo_pwm.pwm_unit [R1];
// system_demo_pwm.time_unit [R2];
// system_demo_pwm.time_unit [R3];
// system_demo_pwm.pwm_unit [R4];
// system_demo_pwm.time_unit [R5];
switch ( new_state )
{
case ST_WAIT : // disable all
set_new_pwm ( 0 );
break;
case ST_TIME_R2 : // start
set_new_pwm ( system_demo_pwm.pwm_unit[R1] );
temp_falling.pwm_start = system_demo_pwm.pwm_unit[R1];
temp_falling.pwm_end = system_demo_pwm.pwm_unit[R1];
temp_falling.pwm_delta = 0;
break;
case ST_TIME_R3 : // falling
set_new_pwm ( system_demo_pwm.pwm_unit[R1] );
temp_falling.pwm_now = system_demo_pwm.current_pwm;
temp_falling.count_step = system_demo_pwm.time_unit[R3] / TASK_PROCESS_TIME;
temp_falling.pwm_start = system_demo_pwm.pwm_unit[R1];
temp_falling.pwm_end = system_demo_pwm.pwm_unit[R4];
temp_falling.pwm_delta = (temp_falling.pwm_start - temp_falling.pwm_end ) / (float)temp_falling.count_step;
break;
case ST_PWM_R4: // line
set_new_pwm ( system_demo_pwm.pwm_unit[R4] );
break;
case ST_TIME_R5:
set_new_pwm ( system_demo_pwm.current_pwm );
temp_falling.pwm_now = system_demo_pwm.current_pwm;
temp_falling.count_step = system_demo_pwm.time_unit[R5] / TASK_PROCESS_TIME;
temp_falling.pwm_start = system_demo_pwm.current_pwm;
temp_falling.pwm_end = 0;
temp_falling.pwm_delta = temp_falling.pwm_start / (float)temp_falling.count_step;
break;
}
system_demo_pwm.state = new_state;
}
//-------------------------------------------------------
void decode_input_data ( void )
{
int foo;
// R1 (0-1024) value PWM1
unsigned long ui_temp;
#ifdef NO_EXT_KEY
in_r_value[R1] = 1024;
in_r_value[R2] = 512;
in_r_value[R3] = 128;
in_r_value[R4] = 512;
in_r_value[R5] = 512;
#endif
#define max_input_analog_value 1023
// get pwm1
ui_temp = get_percent_from_value( in_r_value[R1],max_input_analog_value );
system_demo_pwm.pwm_unit[R1] = get_value_from_percent( ui_temp, MAX_RESOLUTION_PWM );
// get time1 R2
ui_temp = get_percent_from_value( in_r_value[R2],1024 );
system_demo_pwm.time_unit[R2] = get_value_from_percent( ui_temp,10000 ); // 10 sec
// get time2 R3
ui_temp = get_percent_from_value( in_r_value[R3],max_input_analog_value );
system_demo_pwm.time_unit[R3] = get_value_from_percent( ui_temp,10000 ); // 10 sec
// disable incorrect time setting
if ( (system_demo_pwm.time_unit[R2] + system_demo_pwm.time_unit[R3]) > 10000 )
system_demo_pwm.time_unit[R3] = system_demo_pwm.time_unit[R2] / 2;
//-----------------------
// get pwm R4
ui_temp = get_percent_from_value( in_r_value[R4],max_input_analog_value );
system_demo_pwm.pwm_unit[R4] = get_value_from_percent( ui_temp,MAX_RESOLUTION_PWM );
// get time R5
ui_temp = get_percent_from_value( in_r_value[R5],max_input_analog_value );
system_demo_pwm.time_unit[R5] = get_value_from_percent( ui_temp,10000 ); // 10 sec
#ifdef DEBUG
for ( foo = 0; foo < 5; foo ++ )
{
switch ( foo )
{
case R2:
case R3:
case R5:
// Serial.print("time_unit["); Serial.print(foo); Serial.print("] = ");
// Serial.println( system_demo_pwm.time_unit[foo]);
sprintf ( debug_str,"time_unit[%d] = %d " ,foo, system_demo_pwm.time_unit[foo] );
Serial.println ( debug_str );
break;
default:
sprintf ( debug_str,"pwm_unit[%d] = %d " ,foo, system_demo_pwm.pwm_unit[foo] );
Serial.println ( debug_str );
break;
}
}
#endif
}
void manual_stop_system ( void )
{
prepare_new_state (ST_TIME_R5);
#ifdef DEBUG
int foo = ST_TIME_R5;
sprintf ( debug_str,"time_unit[%d] = %d " ,foo, system_demo_pwm.time_unit[foo] );
Serial.println ( debug_str );
sprintf ( debug_str,"pwm_unit[%d] = %d " ,foo, system_demo_pwm.pwm_unit[foo] );
Serial.println ( debug_str );
#endif
}
TE_TIMER programm_count_down_uint16 ( unsigned short *timer , unsigned char shift )
{
if (*timer > 0 )
{
if (*timer > shift )
{
*timer -= shift;
return TIMER_RUN;
}
else
{
*timer = 0;
return TIMER_EXE;
}
}
return TIMER_DISABLED;
}
TE_TIMER programm_count_down_uint32 ( unsigned long *timer , unsigned long shift )
{
if (*timer > 0 )
{
if (*timer > shift )
{
*timer -= shift;
return TIMER_RUN;
}
else
{
*timer = 0;
return TIMER_EXE;
}
}
return TIMER_DISABLED;
}
TE_TIMER system_delay_uint32 ( unsigned long *timer , unsigned long shift )
{
if ( *timer > 0 )
{
if (*timer > shift )
{
*timer -= shift;
return TIMER_RUN;
}
else
{ // save delta time
*timer = ( shift - *timer );
return TIMER_EXE;
}
}
return TIMER_DISABLED;
}
void key_function ( void )
{
#ifndef NO_EXT_KEY
TE_TIMER status;
if ( digitalRead(digi_start_pin))
{
status = programm_count_down_uint32 (&system_demo_pwm.time_start_key_press, TASK_PROCESS_TIME);
switch ( status )
{
case TIMER_EXE:
case TIMER_DISABLED:
system_demo_pwm.key_status = 1;
break;
}
} else {
system_demo_pwm.time_start_key_press = DEBOUNCE_TIME;
status = programm_count_down_uint32 (&system_demo_pwm.time_start_key_un_press, TASK_PROCESS_TIME);
switch ( status )
{
case TIMER_EXE:
case TIMER_DISABLED:
system_demo_pwm.key_status = 0;
break;
}
}
#endif
}
void event_task()
{
TE_TIMER status;
key_function ();
if ( system_demo_pwm.state == ST_WAIT ) return;
switch ( system_demo_pwm.state )
{
//----------------------------------------
case ST_TIME_R2:
// sprintf ( debug_str,"time [%d]" , system_demo_pwm.time_unit[R2] );
// Serial.println ( debug_str );
status = programm_count_down_uint32 (&system_demo_pwm.time_unit[R2], TASK_PROCESS_TIME);
switch ( status )
{
case TIMER_EXE:
case TIMER_DISABLED:
prepare_new_state(ST_TIME_R3);
break;
case TIMER_RUN:
break;
}
break;
//----------------------------------------
case ST_TIME_R3:
status = programm_count_down_uint32 (&temp_falling.count_step, 1);
switch ( status )
{
case TIMER_EXE:
case TIMER_DISABLED:
prepare_new_state(ST_PWM_R4);
break;
case TIMER_RUN:
if ( temp_falling.pwm_now > temp_falling.pwm_delta )
{
temp_falling.pwm_now -= temp_falling.pwm_delta;
} else temp_falling.pwm_now = 0;
set_new_pwm ( temp_falling.pwm_now );
break;
}
break;
//----------------------------------------
case ST_PWM_R4:
// analogWrite(out_pwm_pin, system_demo_pwm.pwm_unit[R4])
break;
//----------------------------------------
case ST_TIME_R5:
status = programm_count_down_uint32 (&temp_falling.count_step, 1);
switch ( status )
{
case TIMER_EXE:
case TIMER_DISABLED:
prepare_new_state(ST_WAIT);
break;
case TIMER_RUN:
if ( temp_falling.pwm_now > temp_falling.pwm_delta )
{
temp_falling.pwm_now -= temp_falling.pwm_delta;
} else temp_falling.pwm_now = 0;
set_new_pwm ( temp_falling.pwm_now );
break;
}
break;
//----------------------------------------
}
}
void get_analog_config_system (void)
{
int foo;
for ( foo = 0; foo < count_element_array(input_array_pin); foo ++ )
{
in_r_value[foo] = analogRead ( input_array_pin[foo] ); // read the input pin
}
}
void loop()
{
static unsigned long task_time;
static unsigned long key_time_start_press;
static unsigned long key_time_start_unpress;
TE_TIMER status;
static unsigned long hw_old_system_timer = 0;
unsigned long hw_current_system_timer = 0;
unsigned long delta_task_timer;
if ( system_demo_pwm.state == ST_WAIT )
{
if ( system_demo_pwm.key_status )
{
get_analog_config_system();
decode_input_data ( );
prepare_new_state (1);
}
}
else
{
if ( system_demo_pwm.state != ST_TIME_R5 )
if ( !system_demo_pwm.key_status ) manual_stop_system();
}
hw_current_system_timer = millis();
delta_task_timer = hw_current_system_timer - hw_old_system_timer;
hw_old_system_timer = hw_current_system_timer;
status = system_delay_uint32 ( &task_time, delta_task_timer );
switch ( status )
{
case TIMER_EXE:
case TIMER_DISABLED:
task_time += TASK_PROCESS_TIME;
event_task();
// Serial.println("exe");
break;
case TIMER_RUN:
break;
}
// - - - - - - - - - - -
#ifdef NO_EXT_KEY
if ( system_demo_pwm.state == ST_WAIT )
if ( system_demo_pwm.key_status == 0 )
{
// Serial.println(" key 0");
status = programm_count_down_uint32 ( &key_time_start_press, delta_task_timer );
switch ( status )
{
case TIMER_EXE:
case TIMER_DISABLED:
system_demo_pwm.key_status = 1;
key_time_start_unpress = 10000;
Serial.println("set key start");
break;
case TIMER_RUN:
break;
}
}
if ( system_demo_pwm.state == ST_PWM_R4 )
if ( system_demo_pwm.key_status == 1 )
{
status = programm_count_down_uint32 ( &key_time_start_unpress, delta_task_timer );
switch ( status )
{
case TIMER_EXE:
case TIMER_DISABLED:
system_demo_pwm.key_status = 0;
key_time_start_press = 5000;
Serial.println("set key end");
break;
case TIMER_RUN:
break;
}
}
#endif
}
доброй ночи )
update: pwm работает.
add max_input_analog_value
максимальные значения прописал неправильно, с вледующем апдейте подправлю, просто обратите внимание
старый код удалил, там много ошибок
пример на емуляторе
pwm_unit[0] = 255
time_unit[1] = 5000
time_unit[2] = 1200
pwm_unit[3] = 127
time_unit[4] = 5000
20:52:16.441 set new state 0
............ pwm: 0
............ set key start
............ pwm_unit[0] = 255
............ time_unit[1] = 5000
............ time_unit[2] = 1200
............ pwm_unit[3] = 127
............ time_unit[4] = 5000
20:52:16.605 set new state 1
20:52:21.654 set new state 2
20:52:23.060 set new state 3 pwm: 127
20:52:32.960 set key end
20:52:32.960 set new state 4
............ time_unit[4] = 5000
............ pwm_unit[4] = 0
............ pwm: 126
20:52:37.975 pwm: 0
RAW DATA LOG
set new state 0
pwm: 0
set key start
pwm_unit[0] = 255
time_unit[1] = 5000
time_unit[2] = 1200
pwm_unit[3] = 127
time_unit[4] = 5000
set new state 1
pwm: 255
set new state 2
pwm: 253
pwm: 252
pwm: 251
pwm: 250
pwm: 249
pwm: 248
pwm: 247
pwm: 246
pwm: 245
pwm: 244
pwm: 243
pwm: 242
pwm: 241
pwm: 240
pwm: 239
pwm: 237
pwm: 236
pwm: 235
pwm: 234
pwm: 233
pwm: 232
pwm: 231
pwm: 230
pwm: 229
pwm: 228
pwm: 227
pwm: 226
pwm: 225
pwm: 224
pwm: 223
pwm: 221
pwm: 220
pwm: 219
pwm: 218
pwm: 217
pwm: 216
pwm: 215
pwm: 214
pwm: 213
pwm: 212
pwm: 211
pwm: 210
pwm: 209
pwm: 208
pwm: 207
pwm: 205
pwm: 204
pwm: 203
pwm: 202
pwm: 201
pwm: 200
pwm: 199
pwm: 198
pwm: 197
pwm: 196
pwm: 195
pwm: 194
pwm: 193
pwm: 192
pwm: 191
pwm: 189
pwm: 188
pwm: 187
pwm: 186
pwm: 185
pwm: 184
pwm: 183
pwm: 182
pwm: 181
pwm: 180
pwm: 179
pwm: 178
pwm: 177
pwm: 176
pwm: 175
pwm: 173
pwm: 172
pwm: 171
pwm: 170
pwm: 169
pwm: 168
pwm: 167
pwm: 166
pwm: 165
pwm: 164
pwm: 163
pwm: 162
pwm: 161
pwm: 160
pwm: 159
pwm: 157
pwm: 156
pwm: 155
pwm: 154
pwm: 153
pwm: 152
pwm: 151
pwm: 150
pwm: 149
pwm: 148
pwm: 147
pwm: 146
pwm: 145
pwm: 144
pwm: 143
pwm: 141
pwm: 140
pwm: 139
pwm: 138
pwm: 137
pwm: 136
pwm: 135
pwm: 134
pwm: 133
pwm: 132
pwm: 131
pwm: 130
pwm: 129
pwm: 128
set new state 3
pwm: 127
set key end
set new state 4
time_unit[4] = 5000
pwm_unit[4] = 0
pwm: 126
pwm: 125
pwm: 124
pwm: 123
pwm: 122
pwm: 121
pwm: 120
pwm: 119
pwm: 118
pwm: 117
pwm: 116
pwm: 115
pwm: 114
pwm: 113
pwm: 112
pwm: 111
pwm: 110
pwm: 109
pwm: 108
pwm: 107
pwm: 106
pwm: 105
pwm: 104
pwm: 103
pwm: 102
pwm: 101
pwm: 100
pwm: 99
pwm: 98
pwm: 97
pwm: 96
pwm: 95
pwm: 94
pwm: 93
pwm: 92
pwm: 91
pwm: 90
pwm: 89
pwm: 88
pwm: 87
pwm: 86
pwm: 85
pwm: 84
pwm: 83
pwm: 82
pwm: 81
pwm: 80
pwm: 79
pwm: 78
pwm: 77
pwm: 76
pwm: 75
pwm: 74
pwm: 73
pwm: 72
pwm: 71
pwm: 70
pwm: 69
pwm: 68
pwm: 67
pwm: 66
pwm: 65
pwm: 64
pwm: 63
pwm: 62
pwm: 61
pwm: 60
pwm: 59
pwm: 58
pwm: 57
pwm: 56
pwm: 55
pwm: 54
pwm: 53
pwm: 52
pwm: 51
pwm: 50
pwm: 49
pwm: 48
pwm: 47
pwm: 46
pwm: 45
pwm: 44
pwm: 43
pwm: 42
pwm: 41
pwm: 40
pwm: 39
pwm: 38
pwm: 37
pwm: 36
pwm: 35
pwm: 34
pwm: 33
pwm: 32
pwm: 31
pwm: 30
pwm: 29
pwm: 28
pwm: 27
pwm: 26
pwm: 25
pwm: 24
pwm: 23
pwm: 22
pwm: 21
pwm: 20
pwm: 19
pwm: 18
pwm: 17
pwm: 16
pwm: 15
pwm: 14
pwm: 13
pwm: 12
pwm: 11
pwm: 10
pwm: 9
pwm: 8
pwm: 7
pwm: 6
pwm: 5
pwm: 4
pwm: 3
pwm: 2
pwm: 1
pwm: 0
set new state 0
set key start
pwm_unit[0] = 255
time_unit[1] = 5000
time_unit[2] = 1200
pwm_unit[3] = 127
time_unit[4] = 5000
set new state 1
pwm: 255
set new state 2
pwm: 253
pwm: 252
pwm: 251
pwm: 250
pwm: 249
pwm: 248
pwm: 247
pwm: 246
pwm: 245
pwm: 244
pwm: 243
pwm: 242
pwm: 241
pwm: 240
pwm: 239
pwm: 237
pwm: 236
pwm: 235
pwm: 234
pwm: 233
pwm: 232
pwm: 231
pwm: 230
pwm: 229
pwm: 228
pwm: 227
pwm: 226
pwm: 225
pwm: 224
pwm: 223
pwm: 221
pwm: 220
pwm: 219
pwm: 218
pwm: 217
pwm: 216
pwm: 215
pwm: 214
pwm: 213
pwm: 212
pwm: 211
pwm: 210
pwm: 209
pwm: 208
pwm: 207
pwm: 205
pwm: 204
pwm: 203
pwm: 202
pwm: 201
pwm: 200
pwm: 199
pwm: 198
pwm: 197
pwm: 196
pwm: 195
pwm: 194
pwm: 193
pwm: 192
pwm: 191
pwm: 189
pwm: 188
pwm: 187
pwm: 186
pwm: 185
pwm: 184
pwm: 183
pwm: 182
pwm: 181
pwm: 180
pwm: 179
pwm: 178
pwm: 177
pwm: 176
pwm: 175
pwm: 173
pwm: 172
pwm: 171
pwm: 170
pwm: 169
pwm: 168
pwm: 167
pwm: 166
pwm: 165
pwm: 164
pwm: 163
pwm: 162
pwm: 161
pwm: 160
pwm: 159
pwm: 157
pwm: 156
pwm: 155
pwm: 154
pwm: 153
pwm: 152
pwm: 151
pwm: 150
pwm: 149
pwm: 148
pwm: 147
pwm: 146
pwm: 145
pwm: 144
pwm: 143
pwm: 141
pwm: 140
pwm: 139
pwm: 138
pwm: 137
pwm: 136
pwm: 135
pwm: 134
pwm: 133
pwm: 132
pwm: 131
pwm: 130
pwm: 129
pwm: 128
set new state 3
pwm: 127
set key end
set new state 4
time_unit[4] = 5000
pwm_unit[4] = 0
pwm: 126
pwm: 125
pwm: 124
pwm: 123
pwm: 122
pwm: 121
pwm: 120
pwm: 119
pwm: 118
pwm: 117
pwm: 116
pwm: 115
pwm: 114
pwm: 113
pwm: 112
pwm: 111
pwm: 110
pwm: 109
pwm: 108
pwm: 107
pwm: 106
pwm: 105
pwm: 104
pwm: 103
pwm: 102
pwm: 101
pwm: 100
pwm: 99
pwm: 98
pwm: 97
pwm: 96
pwm: 95
pwm: 94
pwm: 93
pwm: 92
pwm: 91
pwm: 90
pwm: 89
pwm: 88
pwm: 87
pwm: 86
pwm: 85
pwm: 84
pwm: 83
pwm: 82
pwm: 81
pwm: 80
pwm: 79
pwm: 78
pwm: 77
pwm: 76
pwm: 75
pwm: 74
pwm: 73
pwm: 72
pwm: 71
pwm: 70
pwm: 69
pwm: 68
pwm: 67
pwm: 66
pwm: 65
pwm: 64
pwm: 63
pwm: 62
pwm: 61
pwm: 60
pwm: 59
pwm: 58
pwm: 57
pwm: 56
pwm: 55
pwm: 54
pwm: 53
pwm: 52
pwm: 51
pwm: 50
pwm: 49
pwm: 48
pwm: 47
pwm: 46
pwm: 45
pwm: 44
pwm: 43
pwm: 42
pwm: 41
pwm: 40
pwm: 39
pwm: 38
pwm: 37
pwm: 36
pwm: 35
pwm: 34
pwm: 33
pwm: 32
pwm: 31
pwm: 30
pwm: 29
pwm: 28
pwm: 27
pwm: 26
pwm: 25
pwm: 24
pwm: 23
pwm: 22
pwm: 21
pwm: 20
pwm: 19
pwm: 18
pwm: 17
pwm: 16
pwm: 15
pwm: 14
pwm: 13
pwm: 12
pwm: 11
pwm: 10
pwm: 9
pwm: 8
pwm: 7
pwm: 6
pwm: 5
pwm: 4
pwm: 3
pwm: 2
pwm: 1
pwm: 0
set new state 0
set key start
pwm_unit[0] = 255
time_unit[1] = 5000
time_unit[2] = 1200
pwm_unit[3] = 127
time_unit[4] = 5000
set new state 1
pwm: 255
set new state 2
pwm: 253
pwm: 252
pwm: 251
pwm: 250
pwm: 249
pwm: 248
pwm: 247
pwm: 246
pwm: 245
pwm: 244
pwm: 243
pwm: 242
pwm: 241
pwm: 240
pwm: 239
pwm: 237
pwm: 236
pwm: 235
pwm: 234
pwm: 233
pwm: 232
pwm: 231
pwm: 230
pwm: 229
pwm: 228
pwm: 227
pwm: 226
pwm: 225
pwm: 224
pwm: 223
pwm: 221
pwm: 220
pwm: 219
pwm: 218
pwm: 217
pwm: 216
pwm: 215
pwm: 214
pwm: 213
pwm: 212
pwm: 211
pwm: 210
pwm: 209
pwm: 208
pwm: 207
pwm: 205
pwm: 204
pwm: 203
pwm: 202
pwm: 201
pwm: 200
pwm: 199
pwm: 198
pwm: 197
pwm: 196
pwm: 195
pwm: 194
pwm: 193
pwm: 192
pwm: 191
pwm: 189
pwm: 188
pwm: 187
pwm: 186
pwm: 185
pwm: 184
pwm: 183
pwm: 182
pwm: 181
pwm: 180
pwm: 179
pwm: 178
pwm: 177
pwm: 176
pwm: 175
pwm: 173
pwm: 172
pwm: 171
pwm: 170
pwm: 169
pwm: 168
pwm: 167
pwm: 166
pwm: 165
pwm: 164
pwm: 163
pwm: 162
pwm: 161
pwm: 160
pwm: 159
pwm: 157
pwm: 156
pwm: 155
pwm: 154
pwm: 153
pwm: 152
pwm: 151
pwm: 150
pwm: 149
pwm: 148
pwm: 147
pwm: 146
pwm: 145
pwm: 144
pwm: 143
pwm: 141
pwm: 140
pwm: 139
pwm: 138
pwm: 137
pwm: 136
pwm: 135
pwm: 134
pwm: 133
pwm: 132
pwm: 131
pwm: 130
pwm: 129
pwm: 128
set new state 3
pwm: 127
set key end
set new state 4
time_unit[4] = 5000
pwm_unit[4] = 0
pwm: 126
pwm: 125
pwm: 124
pwm: 123
pwm: 122
pwm: 121
pwm: 120
pwm: 119
pwm: 118
pwm: 117
pwm: 116
pwm: 115
pwm: 114
pwm: 113
pwm: 112
pwm: 111
pwm: 110
pwm: 109
pwm: 108
pwm: 107
pwm: 106
pwm: 105
pwm: 104
pwm: 103
pwm: 102
pwm: 101
pwm: 100
pwm: 99
pwm: 98
pwm: 97
pwm: 96
pwm: 95
pwm: 94
pwm: 93
pwm: 92
pwm: 91
pwm: 90
pwm: 89
pwm: 88
pwm: 87
pwm: 86
pwm: 85
pwm: 84
pwm: 83
pwm: 82
pwm: 81
pwm: 80
pwm: 79
pwm: 78
pwm: 77
pwm: 76
pwm: 75
pwm: 74
pwm: 73
pwm: 72
pwm: 71
pwm: 70
pwm: 69
pwm: 68
pwm: 67
pwm: 66
pwm: 65
pwm: 64
pwm: 63
pwm: 62
pwm: 61
pwm: 60
pwm: 59
pwm: 58
pwm: 57
pwm: 56
pwm: 55
pwm: 54
pwm: 53
pwm: 52
pwm: 51
pwm: 50
pwm: 49
pwm: 48
pwm: 47
pwm: 46
pwm: 45
pwm: 44
pwm: 43
pwm: 42
pwm: 41
pwm: 40
pwm: 39
pwm: 38
pwm: 37
pwm: 36
pwm: 35
pwm: 34
pwm: 33
pwm: 32
pwm: 31
pwm: 30
pwm: 29
pwm: 28
pwm: 27
pwm: 26
pwm: 25
pwm: 24
pwm: 23
pwm: 22
pwm: 21
pwm: 20
pwm: 19
pwm: 18
pwm: 17
pwm: 16
pwm: 15
pwm: 14
pwm: 13
pwm: 12
pwm: 11
pwm: 10
pwm: 9
pwm: 8
pwm: 7
pwm: 6
pwm: 5
pwm: 4
pwm: 3
pwm: 2
pwm: 1
pwm: 0
set new state 0
set key start
pwm_unit[0] = 255
time_unit[1] = 5000
time_unit[2] = 1200
pwm_unit[3] = 127
time_unit[4] = 5000
set new state 1
pwm: 255
set new state 2
pwm: 253
pwm: 252
pwm: 251
pwm: 250
pwm: 249
pwm: 248
pwm: 247
pwm: 246
pwm: 245
pwm: 244
pwm: 243
pwm: 242
pwm: 241
pwm: 240
pwm: 239
pwm: 237
pwm: 236
pwm: 235
pwm: 234
pwm: 233
pwm: 232
pwm: 231
pwm: 230
pwm: 229
pwm: 228
pwm: 227
pwm: 226
pwm: 225
pwm: 224
pwm: 223
pwm: 221
pwm: 220
pwm: 219
pwm: 218
pwm: 217
pwm: 216
pwm: 215
pwm: 214
pwm: 213
pwm: 212
pwm: 211
pwm: 210
pwm: 209
pwm: 208
pwm: 207
pwm: 205
pwm: 204
pwm: 203
pwm: 202
pwm: 201
pwm: 200
pwm: 199
pwm: 198
pwm: 197
pwm: 196
pwm: 195
pwm: 194
pwm: 193
pwm: 192
pwm: 191
pwm: 189
pwm: 188
pwm: 187
pwm: 186
pwm: 185
pwm: 184
pwm: 183
pwm: 182
pwm: 181
pwm: 180
pwm: 179
pwm: 178
pwm: 177
pwm: 176
pwm: 175
pwm: 173
pwm: 172
pwm: 171
pwm: 170
pwm: 169
pwm: 168
pwm: 167
pwm: 166
pwm: 165
pwm: 164
pwm: 163
pwm: 162
pwm: 161
pwm: 160
pwm: 159
pwm: 157
pwm: 156
pwm: 155
pwm: 154
pwm: 153
pwm: 152
pwm: 151
pwm: 150
pwm: 149
pwm: 148
pwm: 147
pwm: 146
pwm: 145
pwm: 144
pwm: 143
pwm: 141
pwm: 140
pwm: 139
pwm: 138
pwm: 137
pwm: 136
pwm: 135
pwm: 134
pwm: 133
pwm: 132
pwm: 131
pwm: 130
pwm: 129
pwm: 128
set new state 3
pwm: 127
set key end
set new state 4
time_unit[4] = 5000
pwm_unit[4] = 0
pwm: 126
pwm: 125
pwm: 124
pwm: 123
pwm: 122
pwm: 121
pwm: 120
pwm: 119
pwm: 118
pwm: 117
pwm: 116
pwm: 115
pwm: 114
pwm: 113
pwm: 112
pwm: 111
pwm: 110
pwm: 109
pwm: 108
pwm: 107
pwm: 106
pwm: 105
pwm: 104
pwm: 103
pwm: 102
pwm: 101
pwm: 100
pwm: 99
pwm: 98
pwm: 97
pwm: 96
pwm: 95
pwm: 94
pwm: 93
pwm: 92
pwm: 91
pwm: 90
pwm: 89
pwm: 88
pwm: 87
pwm: 86
pwm: 85
pwm: 84
pwm: 83
pwm: 82
pwm: 81
pwm: 80
pwm: 79
pwm: 78
pwm: 77
pwm: 76
pwm: 75
pwm: 74
pwm: 73
pwm: 72
pwm: 71
pwm: 70
pwm: 69
pwm: 68
pwm: 67
pwm: 66
pwm: 65
pwm: 64
pwm: 63
pwm: 62
pwm: 61
pwm: 60
pwm: 59
pwm: 58
pwm: 57
pwm: 56
pwm: 55
pwm: 54
pwm: 53
pwm: 52
pwm: 51
pwm: 50
pwm: 49
pwm: 48
pwm: 47
pwm: 46
pwm: 45
pwm: 44
pwm: 43
pwm: 42
pwm: 41
pwm: 40
pwm: 39
pwm: 38
pwm: 37
pwm: 36
pwm: 35
pwm: 34
pwm: 33
pwm: 32
pwm: 31
pwm: 30
pwm: 29
pwm: 28
pwm: 27
pwm: 26
pwm: 25
pwm: 24
pwm: 23
pwm: 22
pwm: 21
pwm: 20
pwm: 19
pwm: 18
pwm: 17
pwm: 16
pwm: 15
pwm: 14
pwm: 13
pwm: 12
pwm: 11
pwm: 10
pwm: 9
pwm: 8
pwm: 7
pwm: 6
pwm: 5
pwm: 4
pwm: 3
pwm: 2
pwm: 1
pwm: 0
set new state 0
set key start
pwm_unit[0] = 255
time_unit[1] = 5000
time_unit[2] = 1200
pwm_unit[3] = 127
time_unit[4] = 5000
set new state 1
pwm: 255
set new state 2
pwm: 253
pwm: 252
pwm: 251
pwm: 250
pwm: 249
pwm: 248
pwm: 247
pwm: 246
pwm: 245
pwm: 244
pwm: 243
pwm: 242
pwm: 241
pwm: 240
pwm: 239
pwm: 237
pwm: 236
pwm: 235
pwm: 234
pwm: 233
pwm: 232
pwm: 231
pwm: 230
pwm: 229
pwm: 228
pwm: 227
pwm: 226
pwm: 225
pwm: 224
pwm: 223
pwm: 221
pwm: 220
pwm: 219
pwm: 218
pwm: 217
pwm: 216
pwm: 215
pwm: 214
pwm: 213
pwm: 212
pwm: 211
pwm: 210
pwm: 209
pwm: 208
pwm: 207
pwm: 205
pwm: 204
pwm: 203
pwm: 202
pwm: 201
pwm: 200
pwm: 199
pwm: 198
pwm: 197
pwm: 196
pwm: 195
pwm: 194
pwm: 193
pwm: 192
pwm: 191
pwm: 189
pwm: 188
pwm: 187
pwm: 186
pwm: 185
pwm: 184
pwm: 183
pwm: 182
pwm: 181
pwm: 180
pwm: 179
pwm: 178
pwm: 177
pwm: 176
pwm: 175
pwm: 173
pwm: 172
pwm: 171
pwm: 170
pwm: 169
pwm: 168
pwm: 167
pwm: 166
pwm: 165
pwm: 164
pwm: 163
pwm: 162
pwm: 161
pwm: 160
pwm: 159
pwm: 157
pwm: 156
pwm: 155
pwm: 154
pwm: 153
pwm: 152
pwm: 151
pwm: 150
pwm: 149
pwm: 148
pwm: 147
pwm: 146
pwm: 145
pwm: 144
pwm: 143
pwm: 141
pwm: 140
pwm: 139
pwm: 138
pwm: 137
pwm: 136
pwm: 135
pwm: 134
pwm: 133
pwm: 132
pwm: 131
pwm: 130
pwm: 129
pwm: 128
set new state 3
pwm: 127
set key end
set new state 4
time_unit[4] = 5000
pwm_unit[4] = 0
pwm: 126
pwm: 125
pwm: 124
pwm: 123
pwm: 122
pwm: 121
pwm: 120
pwm: 119
pwm: 118
pwm: 117
pwm: 116
pwm: 115
pwm: 114
pwm: 113
pwm: 112
pwm: 111
pwm: 110
pwm: 109
pwm: 108
pwm: 107
pwm: 106
pwm: 105
pwm: 104
pwm: 103
pwm: 102
pwm: 101
pwm: 100
pwm: 99
pwm: 98
pwm: 97
pwm: 96
pwm: 95
pwm: 94
pwm: 93
pwm: 92
pwm: 91
pwm: 90
pwm: 89
pwm: 88
pwm: 87
pwm: 86
pwm: 85
pwm: 84
pwm: 83
pwm: 82
pwm: 81
pwm: 80
pwm: 79
pwm: 78
pwm: 77
pwm: 76
pwm: 75
pwm: 74
pwm: 73
pwm: 72
pwm: 71
pwm: 70
pwm: 69
pwm: 68
pwm: 67
pwm: 66
pwm: 65
pwm: 64
pwm: 63
pwm: 62
pwm: 61
pwm: 60
pwm: 59
pwm: 58
pwm: 57
pwm: 56
pwm: 55
pwm: 54
pwm: 53
pwm: 52
pwm: 51
pwm: 50
pwm: 49
pwm: 48
pwm: 47
pwm: 46
pwm: 45
pwm: 44
pwm: 43
pwm: 42
pwm: 41
pwm: 40
pwm: 39
pwm: 38
pwm: 37
pwm: 36
pwm: 35
pwm: 34
pwm: 33
pwm: 32
pwm: 31
pwm: 30
pwm: 29
pwm: 28
pwm: 27
pwm: 26
pwm: 25
pwm: 24
pwm: 23
pwm: 22
pwm: 21
pwm: 20
pwm: 19
pwm: 18
pwm: 17
pwm: 16
pwm: 15
pwm: 14
pwm: 13
pwm: 12
pwm: 11
pwm: 10
pwm: 9
pwm: 8
pwm: 7
pwm: 6
pwm: 5
pwm: 4
pwm: 3
pwm: 2
pwm: 1
pwm: 0
set new state 0
set key start
pwm_unit[0] = 255
time_unit[1] = 5000
time_unit[2] = 1200
pwm_unit[3] = 127
time_unit[4] = 5000
set new state 1
pwm: 255
хоть бы что сказал что неверно использую millis()
так вернее )
hw_current_system_timer = millis();
delta_task_timer = hw_current_system_timer - hw_old_system_timer;
hw_old_system_timer = hw_current_system_timer;
marov.a, как ваши дела?
int PWM = 0;
pinMode(PWM, OUTPUT);
analogWrite(13, PWM) если. Этот кусок работает
То нельзя настаивать ногу?
Честно хотел попробовать. Но на ардуино нано отвалился порт юсб. Кому нано нужно. Отдам в хорошие руки ) самовывоз )
Не получается вставить код так красиво как у корефеев форума
на чёрном фоне