118Views2Replies

# Can you help me convert some Basic code to Processing code for calculating 555 IC timing? Answered

I want to modernize this BASIC code that I found for calculating the values of capacitors, or resistors to use for timing with the 555 IC.

/* This BASIC code taken from the Ramsey Electronics
Universal Timer - Oscilator Kit UT5 instructions
I decided to convert it into processing since no one
really uses basic like this anymore. But you still can.
I don't.

10 PRINT "FIND FOR TIME [T], MICROFARADS [C] OR OHMS [R]?"
20 INPUT "ENTER SELECTION: "; X\$
30 IF X\$ = "T" THEN 100
40 IF X\$ = "C" THEN 200
50 IF X\$ = "R" THEN 300
100 INPUT "C1 in microfarads = ";C
110 INPUT "R3 in ohms = ";R
120 PRINT "TIME (seconds) ="; (1.1 *C*.000001)*R
130 PRINT
140 GOTO 10
200 INPUT "Desired TIME in seconds = "; T
210 INPUT "R3 in OHMS = "; R
220 PRINT "Required capacitance in ufd. = "; T/(1.1*.000001*C)
230 PRINT
240 GOTO 10
300 INPUT "Desired TIME in seconds = "; T
310 INPUT "Value of C1 in microfarads = "; C
320 PRINT "Required value of R3 in ohms = "; T/(1.1*.000001*C)
330 PRINT
340 GOTO 10
*/

/**
typedinput taken from http://wiki.processing.org/index.php/Typed_input
@author Tom Carden
*/
// code was also taken from:
// Learning Processing
// Daniel Shiffman
// http://www.learningprocessing.com

// Example 18-1: User input

// Variable to store text currently being typed
String typing = "";

// Variable to store saved text when return is hit
String saved = "";
String typedText = "Find for time [T], microfarads [C] or ohms [R]?";

PFont font;

void setup() {
size(640, 480); //bigger window. Orginal code has small window
font = createFont("CourierNew", 18);
//fixed width font rather than other ugly font
//suggested in original code.
}

void draw() {
/*is this like the equiv to loop in arduino?
I don't know I hate this language anyway.
BASIC is easier to follow, but I wanted
to make this program easiliy
accessible for modern people.*/
background(255);
fill(255,0,0);
textFont(font,18);
// this adds a blinking cursor after your text, at the expense of
//redrawing everything every frame
text(typedText+(frameCount/10 % 2 == 0 ? "_" : ""), 35, 45);
//nice touch orginal coder!
}

void keyPressed() {
if (key == '\n' ) {
saved = typing;
// A String can be cleared by setting it equal to ""
typing = "";
}
if (key == 't' || key == 'T') {
typedText = typedText.substring(0,max(0,typedText.length()-1));
TIME();

}
if (key == 'c' || key == 'C') {
MICROFARADS();
}
if (key == 'r' || key == 'R') {
OHMS();
} else {
//value = 0;
typedText = typedText + key;
}
}

void keyReleased() {
if (key != CODED) {
switch(key) {
case BACKSPACE:
typedText = typedText.substring(0,max(0,typedText.length()-1));
break;
case TAB:
typedText += "    ";
break;
case ENTER:
case RETURN:
// comment out the following two lines to disable line-breaks
typedText += "\n";
break;
case ESC:
case DELETE:
break;
default:
//typedText += key;
}
if (key == 't' || key == 'T') {
typedText = typedText.substring(0,max(0,typedText.length()-1));
}
}
}

void TIME(){
background(255);
fill(255,0,0);

typedText = "\nC1 in microfarads = ";

//typedText = typedText.substring(0,max(0,typedText.length()-1));
//typedText += key;
//keyReleased();

}
void MICROFARADS(){}
void OHMS(){}

Tags:

## Discussions

There is nothing wrong with Basic in the right context, in many area it is still better than many of the alternatives.

I am not sure what your question is here as you seem capable of transcribing the code yourself.

For the amount of use you might get you may as well use one of the on-line calculators or write a spread sheet to solve the equations.

And you thnk that looks clearer than BASIC !