Combining two programs

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

I have 2 programs (attached),

   

One is an on/off program end the other one is an alarm simulation with capsense

   

on the psoc4 kit.

   

Now I want to combine these programs.

   

I've allready tried several combinations, but so far unsuccessfully.

   

Maybe someone can help me with it?

   

Some words are in dutch like:

   

huidigestand means current state

   

vorigestand means   previous state

   

TOETS1 means button1

0 Likes
11 Replies
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

Do you want to have a selection (at powerup) which program should run? Or do you want to have a new program combining their functionality?

0 Likes
Anonymous
Not applicable

I want to have a new program combining their functionality.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Part your two projects into functions:

   

Initialization() // As the name says

   

Perform()  / do the stuff that was in the for(;;) loop

   

Check and rename global variables

   

Open a new project with two topdesign pages, then copy & paste all the stuff.

   

the new main() now will look like

   

Initialization1();

   

Initialization2();

   

for(;;)

   

{

   

Perform1();

   

Perform2();

   

}

   

 

   

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

I have combined the two programs like you suggested.

   

The "aan/uit" (on/off) program seems to function OK but when I switch on capsense it keeps on working.

   

It's supposed to switch off.

   

What did I do wrong?

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

You didn't the combine as I suggested. I told about different functions, so that one (me) could see what belonged to the first project and what to the other. This makes changes and debugging quite more easier.

   

I strongly suggest to update to Creator 4.1. And following an update of the components.

   

There is an error (flagged as warning) in line 250. You forgot parentheses following the "!"

   

 

   

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

I have made some changes in the program to make it more clear what project 1 and -2 is.

   

Also I have attached a word document of the program and visualized program 1 and -2 with colours.

   

I hope you can identify project 1 and -2 now.

   

By the way I have no warnings on my computer when building and running the program.

   

Leo

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Regarding the warning: Did you already upgrade to Creator 4.1?

   

 

   

Bob

0 Likes
Anonymous
Not applicable

I did upgrade to Creator 4.1 following an  update of the components.

   

As regarding to warnings , there are none on my computer.

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

I have combined the two programs.

   

The "aan/uit" (on/off) program seems to function OK but when I switch on capsense it keeps on working.

   

It's supposed to switch off.

   

Maybe someone can help me with it?

   

Some words are in dutch like:

   

huidigestand means current state

   

vorigestand means   previous state

   

TOETS1 means button1

   

What did I do wrong?

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

To make the problem I have more clear I have made a new program (attached).

   

There are 2 buttons (S1/S2) and 3 LED's.

   

Button S1 has a memory state, in order to switch LED2 and LED3.

   

Button S2 switches LED1.

   

My problem: How do I get round the memory state of Button S1.

   

Whenever I try to switch on LED1 with S2 , LED2/LED3 have to go off but they don't.

   

Maybe someone can help me with it?

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

I am afraid that the error is more of a basic way: You did not write a single line of comment. How do you think you will be able to understand your program or find any bugs when it is not commented!

   

Your indentation is not following the program flow.

   

There is still a warning which you could suppress by placing parentheses

   

Your pins for the switches are floating with high z input. You better declare them as resistor pull up and initially drive high.

   

I would (personally) get away from the 0xffs and other values and use boolean variables and logic throughout that project. You will need to
#define FALSE 0
#define TRUE !FALSE

   

Who will know that writing 0xff to an LED will switch it on or off. In 3 months even you will not be able to tell that 😉 use a #define LEDON and LEDOFF

   

 

   

Bob

0 Likes