Loading...
  Show Posts
Pages: [1] 2 3 ... 630
1  Topics / Science and Measurement / Re: RTC Stopwatch on: Today at 12:57:41 pm

maybe this code helps to make your stopwatch - http://playground.arduino.cc/Code/StopWatchClass -
2  Using Arduino / Programming Questions / Re: Zcd(500Hz) Sin(50Hz) change output Zcd to 50Hz on: Today at 12:17:30 pm
You need a state variable and do something like this.

Code:
bool signalOut = false;

void loop()
{
  float value = 10 * sin( millis() *2PI / 1000UL);

  if (pulseDetect() == true) signalOn = true;
  if (abs(value) < 0.00001) signalOn = false;  // zero detect // comparing floats should never be done with an ==

  if (signalOn)
  {
    serial.print(value, DEC);
  }
  else
  {
    serial.println(0, DEC);
  }
}
BTW is this a school assignment?

 
3  Using Arduino / Project Guidance / Re: pseudo random number generator and PWM output on: Today at 12:03:27 pm
oops, redesign smiley-wink



Code:
uint8_t pwm_value = 0;

float signal = 0;

void setup()
{
  Serial.begin(115200);
  Serial.println("polarization scrambler 0.1");

  randomSeed(analogRead(A0)); // to have a bit of a random start
  pinMode(4, OUTPUT);
}

void loop()
{
  int x = random(2)
  digitalWrite(4, x);  // your square wave

  signal = signal + 0.0001;
  if (signal > 2*PI) signal = 0;
  int pwm_value = 127 + 127 * sin(signal);  // make a sinusoidal pwm value

  if (x == 0) pwm_value = 127; // the random square wave works as a gating for the sinus signal making is 0 at random times and sinusoidal the other times.

  analogWrite(9, pwm_value);

  // optional
  Serial.print(millis());
  Serial.print("\t");
  Serial.print(x);
  Serial.print("\t");
  Serial.println(pwm_value);
}
I think I did the other way around, I made the sinus signal random. If this is not what you want can you post a drawing of how the PWM signal should look like (OK randomized will always be different) or as grumpy says, we need proper requirements.


4  General Category / General Discussion / Re: English Electronics Help on: Today at 11:44:32 am
Of course, the simplest is the OR.

A ===\====
           ]===== out
B ===\====


\ is a passive valve (working as a diode)
if A or B is under pressure OUT is under pressure

for an AND port you need active valves that open under pressure of a 3rd tube. (with a spring inside to close it again if pressure is released.
put 2 of those in series and

P ===[A]======== out
P = constant pressure (~ +5V)
if valve A opens uner pressure and valve B opens under pressure => out will have pressure

An invertor is made with a valve that closes under pressure
P ===[in]==== out

homework, design the XOR smiley-wink
5  Using Arduino / Sensors / Re: Import Data from Arduino Serial Monitor to MS Excel on: Today at 11:04:09 am

Quote
All I want is:

1. I want the program to be terminated after 20 seconds.
2. I want the data obtained from serial monitor to come into my excel sheet or matlab. ( avoiding the redundant work of copy paste )
3. Any other suggestions on this regard

You will not get any output any more after 20 seconds, that was your requirement 1.
You need to restart the sketch if you want more.
And yes it does not exit the loop, it just hangs in an endless while.
while(1);  means while(true) do nothing as the ; is an empty statement.

For requirement 2, you should google for GoBetwino, that is a PC application that bridges between Arduino and any PC application. It really works good.



6  Using Arduino / Project Guidance / Re: pseudo random number generator and PWM output on: Today at 10:50:18 am

Here a starter with all elements you mentioned, but it might be useless as I don't know what a polarization scrambler is

Code:
uint8_t pwm_value = 0;

void setup()
{
  Serial.begin(115200);
  Serial.println("polarization scrambler 0.1");

  randomSeed(analogRead(A0)); // to have a bit of a random start
}

void loop()
{
  int x = random(2);
  pwm_value <<= 1 + x;
  analogWrite(9, pwm_value);

  // optional
  Serial.print(millis());
  Serial.println("\t");
  Serial.println(pwm_value);
}
7  Using Arduino / Project Guidance / Re: EEPROM question on: Today at 10:39:43 am
You could write an interpreter that runs on the Arduino and read lines of code from an SD card.
// there exist sketches like this, I do not recall the name now
8  Using Arduino / Programming Questions / Re: Simple addition works out wrong (drives me nuts...) on: Today at 10:32:57 am
Quote
There is no array bounds checking in a compiled language like C.
When using array bounds checking [ABC] all access of the array needs to be checked, except those that can be determined compile time (in theory). Doing ABC runtime adds code like this for every place where you access an array.
Code:
// suppose your original statement
x = array[ i * 4 ];

extents too

index = i*4;
if (index < array.minIndex || index > array.maxIndex)
{
  exit("Array out of bounds error: ", array.name, index, ...);
}
else
{
  x = array[index]; // for example.
}
This slows code down like sand in a gearbox (OK maybe a bit less) and causes a bigger footprint.
In Turbo Pascal and I think in Delphi too, you have directives that can be used in the code to switch on/off the ABC. I do not know such switch for C/C++ ...
Within C the choice was made to make it the responsibility of the programmer and go for performance and small footprint.

Most important argument against ABC is that ABC in fact allows bugs to exist in your code.
You do not want that, no matter which language you use, compiled or interpreted.

There are static code checkers like LINT that can do partial ABC, but still only those with fixed values.

Fortunately C++ allows you to wrap arrays in a class and add bounds checking to them, and you can even add runtime switches to use ABC or not
// such a switch is almost as expensive as the check itself, but OK it's possible.

9  Using Arduino / Programming Questions / Re: Simple addition works out wrong (drives me nuts...) on: May 18, 2013, 04:05:21 pm
Quote
I know but that does not explain why total holds a value before it is assigned one.

Every variable in a computer program is located on a memory address and every memory address holds a value as there are bits in it to hold a value. Maybe meaningless but still.
It is how (memory)chips work. That is also the reason why you better initialize your variables with a known value.
10  Using Arduino / Project Guidance / Re: EEPROM question on: May 18, 2013, 01:40:44 pm
Quote
also, is 256k bit = 32 kbyte? what i the conversion? thank  you
yes as there are still 8 bits in one byte
11  Using Arduino / Project Guidance / Re: Is there another way to upload code to arduino? on: May 18, 2013, 01:39:56 pm
The code is converted to a .hex file and uploaded by a tool called avrdude.exe
The installation of Arduino contains a help document about it.

If you press the shift and upload simultaneously in the IDE you see the command +params used pass by.

12  Using Arduino / Installation & Troubleshooting / Re: Hardware serial woes on: May 18, 2013, 01:30:09 pm
Quote
3) The program continues to run even after the serial port has crashed
The serial port cannot "crash."

A serial port can overflow on the receiving side ...
13  Using Arduino / Installation & Troubleshooting / Re: SoftwareSerial library keywords.txt file out of date on: May 18, 2013, 01:28:05 pm
Thanks for updating, never noticed smiley-wink

You can post it as an issue here - https://github.com/arduino/Arduino - you need an account

If you want I can post it for you.
14  Using Arduino / Sensors / Re: Import Data from Arduino Serial Monitor to MS Excel on: May 18, 2013, 03:10:30 am
what you mean by:   The problem still persists. The program is not terminating. :/


Arduino's cannot terminate, they can go in an endless loop.

Code:
if (accelgyro.testConnection() == false)  /// updated this line
    {
      Serial.println("MPU6050 connection failed");
      while(1); // blocking loop;
    }
this blocks the program when there is no connection

Code:
if (millis() - start == 20000UL) while(1);  // blocking while loop.
}
This blocks when 20 seconds have passed.
15  Community / Bar Sport / Re: Need help creating a, pee driven game for my toilet. on: May 18, 2013, 02:59:42 am
Most women would appreciate a game that inspire men to lift up the seat.
Can you derive a game for that smiley-wink ?
Pages: [1] 2 3 ... 630