Button count

26 views
Skip to first unread message

TeacDance

unread,
Aug 24, 2020, 4:40:21 PM8/24/20
to Ardublock
i making program to wind speed measure i have problem how to count how many high signal will come in 5sec.. i try to use millis for that..ardublock.jpg

HE Qichen

unread,
Aug 24, 2020, 9:38:47 PM8/24/20
to ardu...@googlegroups.com
Could you please show the code generated by ardublock?

On Tue, Aug 25, 2020 at 4:40 AM TeacDance <tero.k...@pairtec.com> wrote:
i making program to wind speed measure i have problem how to count how many high signal will come in 5sec.. i try to use millis for that..ardublock.jpg

--
You received this message because you are subscribed to the Google Groups "Ardublock" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ardublock+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ardublock/27387af7-802a-477d-bf8e-ae98bbe751b9n%40googlegroups.com.

TeacDance

unread,
Aug 26, 2020, 12:08:00 PM8/26/20
to Ardublock
int _ABVAR_1_wind_count = 0 ;
int _ABVAR_2_radius_cm = 0 ;
unsigned long _ABVAR_3_wind_interval = 0UL ;
unsigned long _ABVAR_4_time = 0UL ;
int _ABVAR_5_start = 0 ;
int _ABVAR_6_tila = 0 ;
boolean __ardublockDigitalRead(int pinNumber)
{
  pinMode(pinNumber, INPUT);
  return digitalRead(pinNumber);
}



void setup()
{
  Serial.begin(9600);
  _ABVAR_1_wind_count = 0 ;

  _ABVAR_2_radius_cm = 9 ;

  _ABVAR_3_wind_interval = 5000 ;

}

void loop()
{
  _ABVAR_4_time = millis() ;
  if (( ( _ABVAR_4_time ) >= ( ( _ABVAR_5_start + _ABVAR_3_wind_interval ) ) ))
  {
    Serial.print(_ABVAR_1_wind_count);
    Serial.print(" ");
    Serial.println();
  }
  if (( ( ( _ABVAR_6_tila ) == ( 0 ) ) && ( ( __ardublockDigitalRead(2) ) == ( HIGH ) ) ))
  {
    _ABVAR_6_tila = 1 ;
    _ABVAR_1_wind_count = ( _ABVAR_1_wind_count + 1 ) ;
    _ABVAR_5_start = millis() ;
  }
  if (( ( ( _ABVAR_6_tila ) == ( 1 ) ) && ( ( __ardublockDigitalRead(2) ) == ( LOW ) ) ))
  {
    _ABVAR_6_tila = 0 ;

Noriaki Mitsunaga

unread,
Aug 26, 2020, 10:16:18 PM8/26/20
to ardu...@googlegroups.com
Hi,

How about this?
1) adding a block "set large integer variable" for "start" variable to set "0" in asetukset part.
2) moving the "set large integer variable" for "start" into the "if" block's for time count
3) adding a block "set large integer variable" for "wind_count" variable to set "0" in the "if" block's for time count

If you use a mechanical switch, maybe you need delay for 20ms or so to avoid chattering. Then, adding a block that makes 20ms delay at the end of the loop part.

// Noriaki Mitsunaga

2020年8月25日(火) 5:40 TeacDance <tero.k...@pairtec.com>:
i making program to wind speed measure i have problem how to count how many high signal will come in 5sec.. i try to use millis for that..ardublock.jpg

--

TeacDance

unread,
Aug 28, 2020, 3:46:35 PM8/28/20
to Ardublock
Now it count rotations but when it's active timer start end if i rotate more when d2 is not active..



unsigned long _ABVAR_1_start = 0UL ;
int _ABVAR_2_wind_count = 0 ;
int _ABVAR_3_radius_cm = 0 ;
unsigned long _ABVAR_4_wind_interval = 0UL ;
void __ardublockDigitalWrite(int pinNumber, boolean status)
{
  pinMode(pinNumber, OUTPUT);
  digitalWrite(pinNumber, status);
}

boolean __ardublockDigitalReadPullup(int pinNumber)
{
  pinMode(pinNumber, INPUT_PULLUP);
  return digitalRead(pinNumber);
}


unsigned long _ABVAR_5_time = 0UL ;
int _ABVAR_6_tila = 0 ;
boolean __ardublockDigitalRead(int pinNumber)
{
  pinMode(pinNumber, INPUT);
  return digitalRead(pinNumber);
}



void setup()
{
  Serial.begin(9600);
  _ABVAR_1_start = 0UL ;

  _ABVAR_2_wind_count = 0 ;

  _ABVAR_3_radius_cm = 9 ;

  _ABVAR_4_wind_interval = 5000 ;

  __ardublockDigitalWrite(2, __ardublockDigitalReadPullup(2));

}

void loop()
{
  _ABVAR_5_time = millis() ;
  if (( ( _ABVAR_5_time ) >= ( ( _ABVAR_1_start + _ABVAR_4_wind_interval ) ) ))
  {
    Serial.print(_ABVAR_2_wind_count);
    Serial.print(" ");
    Serial.println();
  }
  if (( ( ( _ABVAR_6_tila ) == ( 0 ) ) && ( ( __ardublockDigitalRead(2) ) == ( HIGH ) ) ))
  {
    _ABVAR_6_tila = 1 ;
    _ABVAR_2_wind_count = ( _ABVAR_2_wind_count + 1 ) ;
    _ABVAR_1_start = millis() ;
  }
  if (( ( ( _ABVAR_6_tila ) == ( 1 ) ) && ( ( __ardublockDigitalRead(2) ) == ( LOW ) ) ))
  {
    _ABVAR_6_tila = 0 ;
  }
  if (( ( _ABVAR_2_wind_count ) == ( _ABVAR_1_start ) ))
  {
    _ABVAR_2_wind_count = 0 ;
  }
}

ardublock.png

Noriaki Mitsunaga

unread,
Aug 29, 2020, 2:01:11 AM8/29/20
to ardu...@googlegroups.com
Hi,

You need to set the "start" variable to the current time when 5 seconds elapsed so that it runs every 5 seconds. And you need to reset the "wind_count" variable at that time to count only the number of pulses in 5 seconds. Please see attached file.

// Noriaki Mitsunaga

2020年8月29日(土) 4:46 TeacDance <tero.k...@pairtec.com>:
unnamed.jpg

Tero Koskela

unread,
Aug 29, 2020, 3:37:29 AM8/29/20
to Noriaki Mitsunaga, ardu...@googlegroups.com
👍👌🏻 Yep now it’s working

Lähetetty iPhonesta

> Noriaki Mitsunaga <mnor...@gmail.com> kirjoitti 29.8.2020 kello 9.01:
>

TeacDance

unread,
Sep 1, 2020, 4:51:21 PM9/1/20
to Ardublock
If somebody interest this is now working.. wind speed meter with bicyle speed sensor
Tuuli_visual.abp

Aldrik Koster

unread,
Sep 2, 2020, 3:32:59 PM9/2/20
to Ardublock
Thank you very much for sharing, very interesting

Op dinsdag 1 september 2020 om 22:51:21 UTC+2 schreef tero.k...@pairtec.com:
Reply all
Reply to author
Forward
0 new messages