Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9220663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:24:10+00:00 2026-06-18T03:24:10+00:00

I have a timer setup that is triggering and reading the iPhone mic input

  • 0

I have a timer setup that is triggering and reading the iPhone mic input level. I have some if statements that say if the incoming volume is “this” then change the views background color to “this”.

Everything works okay but naturally the meter goes in succession of 0,1,2,3,4,5 then back down in the reverse order of 5,4,3,2,1,0. However I do not want this to occur. I want to jump all the way back to “0” when the volume tries to go back down.

So what I did, was create two variables. One called “previousValue” and the other “currentValue” to keep track of where they are in the succession of levels I am at – then one last if statement that says if previousValue > currentValue (going down) then jump back to “0”. However, it’s just not working. Maybe I am doing something wrong here?

A little help would be very appreciated! Thank you! Here is the code so you can get a better look at what I am trying to achieve.

I declare the INT values below the implementation
int previousValue;
int currentValue;

then set a starting point in the viewDidLoad
previousValue = 0;
currentValue = 0;

if (meterResults > 0.0) {
    NSLog(@"0");
    self.view.backgroundColor = [UIColor redColor];
    previousValue = currentValue;
    currentValue = 0;
}

if (meterResults > 0.1){
    NSLog(@"1");
    self.view.backgroundColor = [UIColor yellowColor];
    previousValue = currentValue;
    currentValue = 1;
}

if (meterResults > 0.2){
    NSLog(@"2");
    self.view.backgroundColor = [UIColor blueColor];
    previousValue = currentValue;
    currentValue = 2;
}

if (meterResults > 0.3){
    NSLog(@"3");
    self.view.backgroundColor = [UIColor greenColor];
    previousValue = currentValue;
    currentValue = 3;
}

if (meterResults > 0.4){
    NSLog(@"4");
    self.view.backgroundColor = [UIColor purpleColor];
    previousValue = currentValue;
    currentValue = 4;
}

if (previousValue > currentValue) {

    NSLog(@"Hello, don't go in reverse order go straight to Red");

    self.view.backgroundColor = [UIColor redColor];

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T03:24:11+00:00Added an answer on June 18, 2026 at 3:24 am

    Aroth’s answer is right, but you’ll still have a problem after you take the advice. Since you’re sampling an analog signal, successive measurements will be roughly continuous. If you change the current value to zero, the next value read will appear to your code to be increasing again, which it isn’t.

    Don’t lie about the current value to make the UI behave as you wish. Instead, model the thing you care about explicitly, which is the instantaneous first derivative. That would go like this:

    currentValue = (int)floor(meterResults * 10.0);
    NSInteger currentFirstDerivative = currentValue - previousValue;
    // since the timer repeats at a fixed interval, this difference is like a 1st derivative
    
    if (currentFirstDerivative < 0) {
        // it's going down, make the view red
    } else {
        switch (currentValue) {
        case 1:
            // change colors here
            break;
        case 2:
        // and so on
    }
    
    // now, for next time
    previousValue = currentValue;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some jQuery listeners setup which listen for form input on a type=text
I have a timer that needs to not process its elapsed event handler at
I have a C# program that works with an SQL Server database. The setup
So I setup a System.Timers.Timer and have a handler for the Elapsed event. It
I need some help with my code. I have an UIAlert that pops up
Imagine that I have 6 circles. My timer calls first 2 circles in the
This is my first try into iPhone development and I have some UITableViewController s
I have an audio app that is having some problems with the way iOS
In my ExtJS 4.0.7 app I have some 3rd party javascripts that I need
I have an array setup like the following: services = ['times', 'food', 'messages', 'share']

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.