C :: Using RA2 As Both Input And Interrupt

Feb 16, 2013

I brought some code from a PICDEM DV lab example into a simple program I'd written. The example showed how to use the external interrupt on the PIC16F690 to switch directions in a function.

I've been trying to use that RA2 pin as both the input (start) trigger for one of my functions and as an interrupt to get out of that function, too. So far the interrupt doesn't work, but the function trigger does. Should I use two pushbuttons or add a random timer to the for() loop to execute the function to roll the dice?

Trying to incorporate that example code also seems to have messed up the little random counter [a for() loop] that I used. The dice pattern was reliably random before adding this new stuff, and now I can clearly see repetition.

I'm only just starting a MC class.

Code:
#pragma config FOSC = INTRCIO // Oscillator Selection bit
#pragma config WDTE = OFF // Watchdog Timer Enable bit
#pragma config PWRTE = OFF // Power-up Timer Enable bit

[Code].....

View 3 Replies


ADVERTISEMENT

C :: Disable Interrupt In ARM M0 Program

May 6, 2014

How do i disable the interrupt in this ARM M0 univesity design start program? The design is made for the M0 and echos an inputted char as an integer, it is part of a larger piece of code (which is ommitted for simplicity).Can i do it in the main program(attached) or will i have to edit the assembler code.

Code:

// Cortex-M0 DesignStart C program example
#include <stdio.h>
#include <time.h>
#include <rt_misc.h>
#include <stdlib.h>
}

[code]....

View 2 Replies View Related

C :: Write A Interrupt To Add Another Sensor For Robotic Car?

Mar 30, 2014

This is a program that is for a robotic car. The car has two light sensors on the front to detect when it veers off the road. When a sense is detected on one of the sensors the corresponding motor will halt until the sensor again detects the track. Again two sensors, left and right, and two motors (one per wheel). I have case statements to do the two left and right sensors.

how would I implement a third sensor with an interrupt to halt the car after it senses a stoping line. E.g. the sensor in the middle detects the stopping point so both motors halt.Here is the code I have so far...The cases are the sensor detections.

Code:

#include <hidef.h> /* common defines and macros */
#include "derivative.h" /* derivative-specific definitions */
// Function Prototypes
void init_PWM(void);
void initLCD(void);

[code]....
}

View 4 Replies View Related

C :: How To Delete Files After SIGINT Has Been Send To Interrupt The Process

May 12, 2013

I have a program that makes a directory (temporary) and in it some files that are necessary for computation while program is running. Now suppose a user decides to interrupt the program at some stage. what happens is that the program stops but my folder and files remain.

Q: How to override SIGINT command so that before the the execution stops the folder is deleted ?

View 4 Replies View Related

C++ :: Create Simple Input Interface On Console - Allow To Input Values To Variables

Apr 6, 2013

I am trying to create a simple interface on console to allow to input some values to some variables. For ex:

int main() {
double a = 1.5;
double b = 2.5;
double c = 3.5;
string x;

[Code] ....

However, I want these three to display at the same time (now they display one by one), and in the console window I can move the cursor between input place of a, b and c with "arrow key" of keyboard.

View 2 Replies View Related

C++ :: Deal With A Failed Input Stream And Type Checking Input?

Jun 17, 2014

deal with a failed input stream and type checking input?

I use:

cout << "
Enter a menu option: ";
while(!(cin >> menuGameMode))
{
cin.clear();
while (cin.get() != '
')
continue;
cout << "Enter a menu option: ";
}

Is this the "Best" way to do it?

EDIT: We're assuming input is expecting an int.

View 9 Replies View Related

C :: Getchar - Clear Input Buffer For Next Input Through Scanf

Aug 13, 2014

I would just like to know what does

while( (c =getchar())!='
' && c !=EOF );

do ? and how it do it?

I have see it in a example to clear the input buffer for next input through scanf but does not know its working clearly.

it is used in this example :

Code:
#include<stdio.h>
struct linklist {
char value[20];
struct linklist *next;
};
struct linklist *head,*curr;

[Code] .....

View 4 Replies View Related

C++ :: Delete Invalid Input Until Correct Input Is Entered?

Mar 20, 2014

Program is to add two fractions together like so..

This program adds fractions. ‘Y’ continues, any other key exits program
===================================================
Enter numerator 1 ==> 1
Enter denominator 1 ==> 3
Enter numerator 2 ==> 1
Enter denominator 2 ==> 6
1 1 1
--- + --- = ---
3 6 2
-----------------------------------------------------
Continue? Y or N! ==> n

My question is that i need each input to be a number.
if a character is entered i want it to output something like..

This program adds fractions. ‘Y’ continues, any other key exits program
===================================================
Enter numerator 1 ==> 1
Enter denominator 1 ==> a
You need to enter a number here.
Press any key to continue.

and then clear the part where the letter was entered.

This program adds fractions. ‘Y’ continues, any other key exits program
===================================================
Enter numerator 1 ==> 1
Enter denominator 1 ==>

View 5 Replies View Related

C++ :: Formatted Input Using Cin

Apr 28, 2013

I'm trying to use cin to get input in a specific format.

Say I have this string as an input: "+ Baraq 112540783 AB1234" I want my variables to look like that:

name = "Baraq"
id = 112540783
book = "AB1234"

now I am sure there is something with providing the format of the input " %s %s %s" or something like that, just not sure how to use it.

View 5 Replies View Related

C :: How To Input With Space

Sep 20, 2014

how to input with space what i mean is like this, for example:

Product Code: 0000001
Product Name: Mobile Phone

if the users input is like that in the (Product Name)it will skip the next input that is the

Price: Quantity: 100
Manufacturer: Alcatel

something like that...

Heres the code

Code:

if(b<=10)
{/*Start for IF Statement*/

for(a=1;a<=b;a++)
{/*Start of FOR loop*/
printf("
");
printf("Product Code : ");
scanf("%s", &prod_code);
}

[code]....

View 14 Replies View Related

C :: Redefinition Of Input

Jan 22, 2013

I am trying to make a poker scoring code and am struggling a bit with the 'picture cards'. The user inputs the handfor example 3c 7d 9h js ad.I have worked out nearly all of the source code, except straights that include jack queen king ace.Is there anyway that when a user types in J the code will recognize it as 11, then queen as 12, etc etc. So from there I could still use the same code I have already made.Here is the part of my code that works out the straight.

Code:

#include<stdio.h>
int main(void)
{ int c;
int n;
int count1[127] = {0};
int count2[127] = {0};
}

[code]...

View 5 Replies View Related

C++ :: How To Input PNG Into Application

Jan 6, 2014

Is there any way to input a picture into an application? I want to make the console of my C++ program display an image across it for a short while. The picture in mind is a gif. If there is no way to make it display in the console, is there a way to make only the image and not the webpage pop up on the screen?

I am trying to replicate the Skyfall "M gets hacked" scene. But this would be useful for other purposes as well.

I am not familiar with using header files or any other files other than the .cpp file and I only use one .cpp file for all my programs.

View 7 Replies View Related

C++ :: While Loop Keeps Asking For Input After EOF

May 11, 2013

This is an example from C++ Primer on while loops shortened for simplicity:

int main() {
int value = 0;
while(cin >> value) cout << value;
return 0;
}

When I compile and run the above code the program keeps asking for input after I input nothing but pressing ENTER no matter how many times. The only way I can get it to stop asking for input is to input something other than an int such as a char or string. Program executes as intended after that. I have googled this issue and read all seemingly relevant results and nothing seems to pertain to my exact problem. I think it may have something to do with my computer's own settings or something and am baffled as to what it may be.

View 10 Replies View Related

C++ :: Cannot Take Input From Files

Apr 28, 2013

Assignment: Write a program that merges the numbers in two files and writes all the numbers into a third file. your program takes input from two different files and writes it output to a third file. Each input file contains a list of numbers of type int in sorted order from the smallest to largest. after the program is run, the output file will contain all the numbers in the two input files in one longer list in sorted order from smallest to largest. your program should define a function that is called with the two input - file streams and the out - put file stream as three arguments.

Okay, here is my code.

#include<iostream>
#include<fstream>
using namespace std;

int main() {
int list1[25];//array for the first list
int list2[25];//array for the second list

[Code] .....

I'm confused about where the two files (which contain lists of numbers) need to be placed in order to be read and if they need to be renamed or something.

View 1 Replies View Related

C++ :: Input Only Values Between 2 - 7

Jan 4, 2015

I want to input only values between 2 - 7 what is wrong?

do{
cout<<"Podaj wykladnik
";
cin>>b;
}while(b<=2 && b>=7);

View 2 Replies View Related

C++ :: Input Value Get Index

Sep 9, 2014

I am trying to get the index of a value by inputting the value:

For example if i have

int arr[5]={22, 85, 58, 78, 69};

indexOfItem(arr, 78);

and have the output be:

the index of the item is: 3

View 3 Replies View Related

C++ :: Using Map Against Defined Input?

Sep 16, 2013

What I want to do is have a defined string as the input and use that to run it against the keys, so I can pull out the values. I have some functions beneath for searching, a possibility would be to parse the input and use something along those lines.

I would like to try and use a map for this.

#include <iostream>
#include <map>
#include <string>

[Code].....

View 6 Replies View Related

C++ :: Take Input And Put That Into Variable

May 12, 2014

So for this function, I'm trying to take an input (may be a user input or an input file) and put that into a variable. The function:

istream & operator>>(istream &is, Event &e)

What direction should I take to implement this?

View 2 Replies View Related

C++ :: How To Do 6 Input File

Dec 5, 2013

How can I put 6 input file into my program.How can I use while to let the 6input file to open automatic?

View 4 Replies View Related

C++ :: Get Input From TXT File?

Mar 26, 2013

So me and my groupmates suddenly have some clutchwork at hand. I was assigned of making an import function that reads through a textfile that looks like this, and store it to a 2D array. Like this [URL]

The columns are Tab-separated however the difference from that image to mine is that i receive a 3x3 matrix with a blank space substituing one of the numbers and i was wondering how could i detect that blank space

View 12 Replies View Related

C++ :: Data Input From Txt

Nov 27, 2012

I have this code.

Code:
#include <string>
#include <iostream>
#include <fstream>
#include <math.h>
#include <sstream>
string scoresort[9];
int HighScore(int PlayerScore){

[Code] ....

Now I can't put data into the array scoresort[x]. I have tried everything. When the scoresort[x] is not an array I can input data. Although when it is an array it crashes my program. It will not process the line.

This is part of the HighScore section for a game that I am currently making.

View 1 Replies View Related

C++ :: Second User Name Input Is Being Skipped

Jan 1, 2014

In this simple end-of-chapter problem, the ages of two people are to be compared and determine who's older. The problem I'm experiencing is that the second user name input is being skipped and going straight to the second users age.

So while running the program it looks something like:

What is user ones name?
<input name>
How old are they?
<input age>
What is user twos name?
How old are they?
<input age>
<if statement result>

Here's my code:

Code: #include <iostream>
#include <string>
using namespace std;
int user_one_age;
int user_two_age;
string user_one_name;
string user_two_name;

[code].....

View 9 Replies View Related

C++ :: Input Integer To A String?

Oct 20, 2014

i wanna put an integer into a string for example:

Code:
string name;
int num=8;
name= "George"
//

I want in the end of George to pas the num variable i ve seen some examples but ive not yet come up with a solution like str.insert();

View 7 Replies View Related

C++ :: Print Out All Input Values

Mar 16, 2013

I have a problem with how to print out all the numbers that the user enters the code looks like this so far:

Code:
#include <iostream>
using namespace std;
int main()

[Code] ....

I want the program to print out all the numbers that the user has entered after the program have said the higest and lowest number is ?. But I do not know how to do this I thought it could be something like this:

Code:
cout << input[0];
//or
cout << input[i];
/*

Because i is the number of how many enters of numbers the user can do*/ But that was totally wrong tried to do another "for loop" in the first for loop but that was meaningless because it can't change anything in the first "for loop".

View 7 Replies View Related

C# :: TexBox User Input To Hex Value

Sep 2, 2012

So I've got this form that a user puts in a numeric value into a text box. This value then has to be placed into a byte string of data so that it can be transmitted over as a packet. Bellow is what I have so far:

Code:
Byte[] OUTBuffer = new byte[65];//Allocate output memory buffer
Byte[] INBuffer = new byte[65]; //Allocate input memory buffer

if (setmSpeed == true)
{
OUTBuffer[0] = 0; //Not used, must be set to 0
OUTBuffer[1] = 0x85; //Command mode

[Code] ....

I've put in red the area where I'm having issues. I've tried different methods and have not been able to get this working yet. It only works if I speciffy the value manually as with OUTBuffer[1] = 0x85;, but I want byte 2 of OUTBuffer[] to be set with what I put in the text box.

View 4 Replies View Related

C :: Flushing Input And Why Do Have To Hit Enter Key Twice

Mar 6, 2015

I wrote a program that reads user input string using fgets() function. After this, program will ask if the user wants to save the string to file or does the user want to change the string or quit without saving. If user wants to change the string this must be made possible by asking for the string again. After this, menu will be printed again printing the choices available.

I had to flush stdin before getting changing input! However, problem is "Why do I have to hit return key 2 times, when I choose 2 and input string again." (I use code block 13.12 with windows 8.1 laptop) */

Code:
#include <stdio.h>
#include <string.h>
#define MAX 50

[Code]....

View 9 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved